I have the next code (make it small & simple),
Why did I get the speed +=
working, although the speed
wasn't initialized at all?
#include <iostream>
using namespace std;
class Vehicle {
protected:
int speed;
public:
virtual void repair(int j) {
cout << "Vehicle " << j << endl;
if (repair())
{
speed += j;
cout << "Speed:" << speed;
}
}
int repair(){ cout << "Vehicle repair " << endl; return 1; }
};
void main() {
Vehicle v; //Car c; CityCar cc;
Vehicle * vp; //Car * cp;
vp = &v;
vp->repair(1);
}