I understand the concept of operator overloading in a fairly basic way. Lets say I have a simple box class.
class Box
{
public:
float volume;
}
Then I use 'new' to assign my pointer variable called Box two new Box types:
int main()
{
Box* Boxes[2];
Box[0] = new Box;
Box[1] = new Box;
Box[0]->volume = 125.0;
Box[1]->volume = 150.0;
If(Box[0] >= Box[1])
cout << "Box[0] is bigger\n";
else
cout << "Box[1] is bigger\n";
return 0;
}
How do I write an overloaded operator function for my Box class that compares the value of each Box's volume variable, when using a pointer. I know how to do this when I declare a box like this:
Box Box1;
Box Box2;
Is this even possible?
class Box
{
public:
float volume;
}
Then I use 'new' to assign my pointer variable called Box two new Box types:
int main()
{
Box* Boxes[2];
Box[0] = new Box;
Box[1] = new Box;
Box[0]->volume = 125.0;
Box[1]->volume = 150.0;
If(Box[0] >= Box[1])
cout << "Box[0] is bigger\n";
else
cout << "Box[1] is bigger\n";
return 0;
}
How do I write an overloaded operator function for my Box class that compares the value of each Box's volume variable, when using a pointer. I know how to do this when I declare a box like this:
Box Box1;
Box Box2;
Is this even possible?
