我有一個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- –