P
Paul Smitton
Hello,
I would like to be able to store some constant data that is specific to each
descendant class.
This data would then be accessable by base class functions. However, I
cannot find out how to do this.
I thought the following would be a practical way of achieving this, but it
will not work.
Any help would be appreciated.
class Vehicle {
private:
static const int int Wheels = 0;
public:
int GetWheels() {
return Wheels;
}
};
class Car: public Vehicle {
private:
static const int Wheels = 4;
};
class Motorbike: public Vehicle {
private:
static const int Wheels = 2;
};
void main() {
Vehicle *myMini = new Car;
n = myMini->Wheels; // n = 0, but i was hoping it
would be 4
}
I would like to be able to store some constant data that is specific to each
descendant class.
This data would then be accessable by base class functions. However, I
cannot find out how to do this.
I thought the following would be a practical way of achieving this, but it
will not work.
Any help would be appreciated.
class Vehicle {
private:
static const int int Wheels = 0;
public:
int GetWheels() {
return Wheels;
}
};
class Car: public Vehicle {
private:
static const int Wheels = 4;
};
class Motorbike: public Vehicle {
private:
static const int Wheels = 2;
};
void main() {
Vehicle *myMini = new Car;
n = myMini->Wheels; // n = 0, but i was hoping it
would be 4
}