Question
In this code the ostream operator is not working properly and the text is not getting printed. Kindly correct this code. class Tyre{ private: int*
In this code the ostream operator is not working properly and the text is not getting printed. Kindly correct this code.
class Tyre{
private:
int* width;
int* aspect_ratio;
int* diameter;
public:
Tyre(int wid, int asp, int diam) {
width = &wid; aspect_ratio = &asp; diameter = ⋄
}
//Constructors, Getters and Destructor
friend ostream& operator << (ostream& out, Tyre t1) {
out << "Tyre Width is : " << t1.width << endl;
out << "Tyre Aspect ratio is : " << *t1.aspect_ratio << endl;
out << "Tyre Diameter is : " << *t1.diameter << endl;
return out;
}
~Tyre() {
delete [] width;
width = nullptr;
delete[] aspect_ratio;
aspect_ratio = nullptr;
delete[] diameter;
diameter = nullptr;
}
};
int main() {
Tyre tNew(12, 10, 13);
cout << tNew;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started