an*****@yahoo.com wrote:
hello,
I have a question regarding how to include classes .
Assuming I have a class called
class paraClass
{
enum eType { eOne, eTwo, eThree };
enum cValue = 4;
static convertToString (int inNumber) { ...}
static convertToNumber (int inString) { ...}
}
now in parent class, which option is better?
1.
class newClass : public paraClass
{
public:
int getValue() const { return myValue * cValue; }
private:
int myValue;
}
2.
class newClass
{
public
int getValue() const { return myValue * (paraClass::cValue);
private
int myValue;
}
Even assuming you modify paraClass to make its members protected
(rather than private) to give the derived class access (and you'd
better give it a protected destructor too just in case), in what way is
a newClass a "type of" paraClass?
It might depend what you are going to use it all for - are you going to
use paraClass for meta-programming because it's useful for that (you
might have another class that has the same names but with different
definitions. You can pass such classes into templates).
Generally inheritance should be used to implement a "is a type of"
design feature and I don't see how that applies above.