I've been learning about Design Patterns and in my implementations of Strategy Design Pattern I discovered that I couldn't declare inheritance in a class definition like so:
class Context
{
private:
Strategy *strategy_;
public:
Context(Strategy* strategy) : strategy_(strategy); // This line
~Context();
void set_strategy(Strategy* strategy);
void DoStuff() const;
};
By changing the default constructor to be within my class definition worked fine
Context(Strategy* strategy=nullptr) : strategy_(strategy){}
Or by removing the inheritance from the definition and defining it outside the class like so.
class Context
{
private:
Strategy *strategy_;
public:
Context(Strategy* strategy); // This line
~Context();
void set_strategy(Strategy* strategy);
void DoStuff() const;
};
Context::Context(Strategy *strategy=nullptr) : strategy_(strategy){} // and this line
I'm curious as to why inheritance can't be declared in the default constructor within the class definition.