I would like to create a base (abstract) class (let it be called type::base ) with some common functionality and a free interface, the problem I came across is the return type of all these methods
class base { public: base(); virtual ~base(); base& with_foo(); base& with_bar(); protected:
Now I can make subtypes, for example:
class my_type : public base { public: myType();
The problem arises when using subtypes such as this:
my_type build_my_type() { return my_type().with_foo().with_bar(); }
This does not compile because we are returning the base instead of my_type.
I know that I can simply:
my_type build_my_type() { my_type ret; ret.with_foo().with_bar(); return ret; }
But I thought, how can I implement it, and I did not find any valid ideas, suggestions?
c ++ inheritance fluent-interface
blaxter
source share