View Single Post
Old Feb 27th, 2006, 3:02 PM   #5
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 4 Kaja Fumei is on a distinguished road
I see the problem now, I wasn't paying too much attention before. Overloaded operators can only be used on the the object "value". If you declare a pointer to an object, any operators you do on that pointer will be done to the pointer, not to the data. So you must declare the car on the stack or if you have a pointer to a Car (call the pointer variable Honda), you can use ++*Honda.

Method one:
    Car Honda;
    Honda.Speeding();    
    Honda.SetSpeed(45);
    Honda.Speeding();
    Honda.Speed();
    Honda.Speeding();
    ++Honda;
    Honda.Speeding();
    ++Honda;
    Honda.Speeding();

Method 2:
    Car * Honda2 = new Car;
    Honda2->Speeding();    
    Honda2->SetSpeed(45);
    Honda2->Speeding();
    Honda2->Speed();
    Honda2->Speeding();
    ++*Honda2;
    Honda2->Speeding();
    ++*Honda2;
    Honda2->Speeding();
    
    delete Honda2;

I ran your code on both of these and it worked fine.
Kaja Fumei is offline   Reply With Quote