I know there are a million posts about this, but I still can’t figure out why this isn’t working =/
this line:
test = new Test2<Test>;
gives me this error:
error C2512: 'Test2<PARENT>' : no appropriate default constructor available
with
[
PARENT=Test
]
code:
template<class PARENT>
class Test2;
////////////////////////////
class Test
{
public:
Test2<Test> *test;
Test()
{
test = new Test2<Test>;
}
};
/////////////////////////////
template<class PARENT>
class Test2
{
public:
PARENT *parent;
};
////////////////////////////
can someone help me out?
At the point of instantiation (i.e. inside the
Testconstructor), all the compiler has so far is a forward declaration ofTest2<>; it doesn’t yet know what constructors are available.To solve, either move the definition of
Test2<>before that ofTest, or move the definition of theTestconstructor outside the class definition (and after the definition ofTest2<>).