Jun 29, 2011 at 5:36pm UTC
Hi,
Say I have a base classe that inherits from another base class, then I derive another class from them. What is the proper way. For example:
class BaseForText
{
public:
virtual void SetText(const TCHAR *text)=0;
}
class BaseForTextAndZammo : public BaseForText
{
public:
virtual void SetZammo(const TCHAR *zammo)=0;
}
class MyTextClass : public BaseForText
{
// here I'd do my constructor and settext
}
class MyTextAndZammo : public MyTextClass
{
// here I'd do my constructor and setzammo
};
But if you create MyTextAndZammo object and assign to a BaseForTextAndZammo variable then it doesn't work right.
So how would you do it so you down't have to duplicate the code from MyTextClass?
TIA!!
Last edited on Jun 29, 2011 at 5:38pm UTC
Jun 29, 2011 at 5:46pm UTC
Of course, MyTextAndZammo is derived from MyTextClass, which is derived from BaseForText, and not BaseForTextAndZammo. Do you want multiple inheritance? C++ supports that.
Jun 30, 2011 at 3:56am UTC
I wanted to reuse the code already done in MyTextClass without it being duplicated in MyTextAndZammo.