So i have a interface class
class interfaceClass
{
public:
virtual void func1( void ) = 0;
virtual void func2( void ) = 0;
protected:
int m_interfaceVar;
}
and a class that inherits from it.
Why can’t i set the member variable of the interface class as follows.
class inhertitedClass : public interfaceClass
{
inheritedClass(int getInt): m_interfaceVar(getInt){};
~inheritedClass(){};
}
and i have to do it like this
class inhertitedClass : public interfaceClass
{
inheritedClass(int getInt){ m_interfaceVar = getInt;}
~inheritedClass(){};
}
I’m sorry if this is a dumb question, but i just ran in to it the other night while i was switching my abstract class into an interface class (the back to an abstract class).
The initializer list in a constructor can specify the ctor for the base classes first and foremost. By depriving
interfaceClassof a (protected) constructor (which it obviously should have) you’ve cut off that lifeline.So add that protected ctor, e.g.:
and then you can do things the right way, namely