You try to override a function based on return type. The class Base::Inner
is not the same as Derived::Inner
, and so you can't override the m
method in the base class from the derived class.
The m
method in the Derived
class needs to return Base::Inner
. However, that will lead to object slicing so you can't do that directly. Instead you either have to return a reference or a pointer.
I suggest the latter, by using std::unique_ptr
.
Maybe something like:
template<typename U>
class Base
{
public:
class Inner { ... };
using inner_ptr = std::unique_ptr<Base<U>::Inner>;
virtual inner_ptr m(const std::string&) = 0;
};
template<typename U>
class Derived : public Base<U>
{
public:
Base<U>::inner_ptr m(const std::string&);
class LocalInner : public Base<U>::Inner { ... };
};
template<typename U>
inline Base<U>::inner_ptr m(const std::string& arg)
{
return Base<U>::inner_ptr(new LocalInner);
}