I have a base class Basedefined in Base.h :
class Base
{ };
And the class template Childthat comes from Baseis defined in Child.h :
#include "Base.h"
template <class T>
class Child : public Base
{ };
Now I want to create some factory methods in the class Base, which should return the class std::shared_ptrto the class Child. To avoid circular dependencies, I tried instead to use forward declaration. So Base.h now looks like this:
class Child;
class Base
{
static std::shared_ptr<Base> CreateChildInt(int i = 0)
{
return std::make_shared<Child<int>>(i);
}
};
However, the definition CreateChildInt()results in the following compiler error:
"C2947: expected '>' to complete the argument template list found by '<'"
, ?
, / ?
:
, factory Base Child, . factory Child, factory :
std::shared_ptr<Base> p = Child<int>::CreateChildInt(3);
<int> , :
std::shared_ptr<Base> p = Base::CreateChildInt(3);