This is partly related to this SO question.
I have two classes, both of them are templated, e.g.:
class Base
{
public:
template< class T > void operator=(T other)
{
//irrelevant
}
Derived toDerived()
{
Derived d;
//do stuff;
return d;
}
};
class Derived: public Base
{
public:
template< class T > void foo( T other )
{
//do stuff
}
};
As you can see, both are templated, and inside of the Base
class function I need to create an instance of Derived
. Of course, the way it is now I'm getting an error Derived does not name a type
. Unfortunately though, I can't just forward-declare Derived
, because it will lead to another error variable 'Derived d ' has initializer but incomplete type
.
From the SO question I mentioned above I understand that the compiler needs to know about all the template parameters to be able to forward-declare it correctly. But obviousle I can't just move Derived
declaration up, because it will lead to exactly same problem, just vice-versa.
Is there a way to accomplish this?