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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!