Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板类的VS编译器错误_C++_Templates_Visual C++ - Fatal编程技术网

C++ 模板类的VS编译器错误

C++ 模板类的VS编译器错误,c++,templates,visual-c++,C++,Templates,Visual C++,VS为这段代码抛出了奇怪的编译器错误,在第9行给了我3个错误。 我以前在其他项目中使用过类似的代码,效果很好。 节点类包含在头中,两个指针在构造函数中都设置为nullptr template<class T> class Edge { public: Edge<T> *next; Node<T> *destination; Edge<T>(); ~Edge(); }; 模板 阶级边缘 { 公众: 边*下一步; 节点

VS为这段代码抛出了奇怪的编译器错误,在第9行给了我3个错误。 我以前在其他项目中使用过类似的代码,效果很好。 节点类包含在头中,两个指针在构造函数中都设置为nullptr

template<class T>
class Edge
{
public:
    Edge<T> *next;
    Node<T> *destination;
    Edge<T>();
    ~Edge();
};
模板
阶级边缘
{
公众:
边*下一步;
节点*目的地;
边();
~Edge();
};


错误C2143:语法错误:缺少“;”在“之前,您是否声明了节点?编译器需要在边缘之前了解节点

这:

#包括
使用名称空间std;
//使用节点的正向声明,以便编译器知道此类型存在。
模板类节点;
模板
阶级边缘
{
公众:
边*下一步;
节点*目的地;
边(){};
~Edge(){};
};
int main(){
边缘测试;

std::cout是否声明了节点?编译器需要在Edge之前了解节点

这:

#包括
使用名称空间std;
//使用节点的正向声明,以便编译器知道此类型存在。
模板类节点;
模板
阶级边缘
{
公众:
边*下一步;
节点*目的地;
边(){};
~Edge(){};
};
int main(){
边缘测试;
标准::cout
error C2143: syntax error: missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
#include <iostream>
using namespace std;

// Use a forward-declaration of Node, so that the compiler knows this type exists.
template<class T> class Node;

template<class T>
class Edge
{
public:
    Edge<T> *next;
    Node<T> *destination;
    Edge<T>(){};
    ~Edge(){};
};

int main() {
    Edge<int> test;
    std::cout<<&test<<std::endl;
    return 0;
}