- Oct 11, 2007
- 1,163
- 4
- 81
*edit* I'm coding in C++
Let say I have a pure virtual base class (call it Base) and two derived classes ClassA and ClassB.
Is there a way to define a constant such that it will be different between the two derived classes but be usable in the base class?
For example, let say I want a constant MAX_VALUE to be 10 in ClassA and 20 in ClassB, and have a function
The only way I can think of doing this is to have a pure virtual function
that is defined in the derived classes.
Let say I have a pure virtual base class (call it Base) and two derived classes ClassA and ClassB.
Is there a way to define a constant such that it will be different between the two derived classes but be usable in the base class?
For example, let say I want a constant MAX_VALUE to be 10 in ClassA and 20 in ClassB, and have a function
Code:
bool Base::compareMax(int value)
{
return (value <= MAX_VALUE);
}
Code:
virtual int getMaxValue()
Last edited:
