Hi There,
I have a bit of problems with implementing multiple levels of interitance and am looking for advice how best to do it.
I start with an interface class looks like:
[code]
class Class1If {
public:
Class1If() {}
virtual ~Class1If() {}
virtual int PubFun() = 0;
protected:
virtual int ProFun() = 0;
virtual int WantToCall() = 0;
};
[code]
Then implementation:
That is fine until I would like to go one level beyond and still access, for example value, so what I try:Code:class Class1 : public Class1If { public: Class1(); ~Class(); virtual int PubFun(); protected: virtual int ProFun(); virtual int WantToCall(); int Value; }; Class1::Class1 { Value = 1; } Class1::~Class1 { Value = 0; } Class1::PubFun() { Value = 2; } Class1::ProFun() { Value = 3; } Class1::WantToCall() { Value = 100; }
And that ends up in a compilation error because multiple level inheritance is not supported by C++.Code:class Class2If : public Class1 { public: Class2If() {} virtual ~Class2If() {} virtual int PubFun() = 0; protected: virtual int ProFun() = 0; } class Class2 : public Class2If { public: Class2If(); virtual ~Class2If(); virtual int PubFun() = 0; protected: virtual int ProFun() = 0; } Class2::Class2 { Value = 1; } Class2::~Class2 { Value = 0; } Class2::PubFun() { Value = 2; } Class2::ProFun() { Value = 3; }
My question is that what is the best way to make sure that both Value and WantToCall() are available in Class2?
Thanks![]()




Reply With Quote