我有一个C++项目链接的问题,我无法弄清楚什么是错的。 代码的笑话。C++未定义的引用链接功能
clitest.cpp
#include <iostream>
#include "node.h"
using namespace std;
int main(int argc, char** argv)
{
node<int> *ndNew = new node<int>(7);
return 0;
}
node.h
#ifndef NODE_H
#define NODE_H
#include <vector>
template <typename T>
class node
{
private:
node<T>* ndFather;
std::vector<node<T>* > vecSons;
public:
T* Data;
node(const T &Data);
};
#endif
node.cpp
#include "node.h"
using namespace std;
template <typename T>
node<T>::node(const T &Data)
{
this->Data = &Data;
this->ndFather = 0;
this->vecSons = (new vector<T>());
};
的是使用编译器指令是
g++ -Wall -g clitest.cpp node.cpp -o clitest
错误日志是这样的
clitest.cpp: In function ‘int main(int, char**)’:
clitest.cpp:8:16: warning: unused variable ‘ndNew’ [-Wunused-variable]
node<int> *ndNew = new node<int>(7);
^
/tmp/cc258ryG.o: In function `main':
clitest.cpp:8: undefined reference to `node<int>::node(int const&)'
collect2: error: ld returned 1 exit status
make: *** [blist] Error 1
我已经花了很多时间像样的量左右移位的代码,试图找出问题,我要么会错过一些基本的东西,或者这件事情我不知道C++链接。
可能重复的[为什么模板只能在头文件中实现?](http://stackoverflow.com/questions/495021/why- –