What I would like, if not with this syntax, but in spirit :
class A
{
virtual A f()=0;
};
class B : public A
{
B f();
};
I do see the problem with the code above : A is virtual, thus no instance of A can be created, hence no instance of A can be returned.
Yet, concrete subclasses of A (e.g. B) will have to implement the function f, which will always be able to return an instance of themselve (e.g. instance of B), i.e. an instance of a subclass of A.
While the above is incorrect and does not compile, is there a way to get something similar valid ? Possibly, but not necessarily, of the like:
class A
{
virtual "a concrete sublclass of A" f()=0;
};
note: I prefer not to return a pointer or a reference, as I would prefer B not to have to manage an instance of itself as attribute.
note: if possible c++11, but curious to hear about newer versions as well