//node.h
#ifndef NODE_H
#define NODE_Htemplate <class T>
class Node{
public:
T data;
Node* next;
Node(const T& d, Node* pNext);
};
#endif
//node.cpp
#include "node.h"template <class T>
Node<T>::Node(const T& d, Node* pNext):data(d), next(pNext){}//main.cpp
#include "node.h"
#include <iostream>
using namespace std;
int main()
{
Node<int> n(3, NULL);
}
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Node<int>::Node<int>(int const &,class Node<int> *)" (??0?$Node@H@@QAE@ABHPAV0@@Z),该符号在函数 _main 中被引用
1>E:\数据结构\haha\Debug\haha.exe : fatal error LNK1120: 1 个无法解析的外部命令ps:如果我将构造函数定义放在node.h中,编译就通过了,请问这是为什么?