模板类:没有默认构造函数

bit*_*ise 3 c++ templates constructor

我知道有关于此的一百万个帖子,但我仍然无法弄清楚为什么这不起作用= /

这一行:

test = new Test2<Test>;
Run Code Online (Sandbox Code Playgroud)

给我这个错误:

error C2512: 'Test2<PARENT>' : no appropriate default constructor available
with
[
    PARENT=Test
]
Run Code Online (Sandbox Code Playgroud)

码:

template<class PARENT>
class Test2;

////////////////////////////

class Test
{
public:
    Test2<Test> *test;

    Test()
    {
        test = new Test2<Test>;
    }
};

/////////////////////////////

template<class PARENT>
class Test2
{
public:
    PARENT *parent;
};

////////////////////////////
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

Oli*_*rth 6

在实例化(即内部的点Test构造函数),所有的编译器至今已是一个向前声明Test2<>; 它还不知道有哪些构造函数可用.

来解决,或者移动的定义Test2<> 之前那的Test,或移动的定义Test构造方法的类定义之外(和之后的定义Test2<>).