//test.h#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
template <typename T>
class test
{
public:
test();
};
#endif // TEST_H_INCLUDED//test.cpp#include "test.h"
template <typename T>
test<T>::test()
{
;
}
//main.cpp#include <iostream>
#include "test.h"
using namespace std;
int main()
{
test <int> t;
return 0;
}
编译的时候提示undefined reference to `test<int>::test()'|但是把 test.cpp的内容剪切到test.h里面的时候 编译就通过了如果不使用容器类也不会有问题的 求解
#define TEST_H_INCLUDED
template <typename T>
class test
{
public:
test();
};
#endif // TEST_H_INCLUDED//test.cpp#include "test.h"
template <typename T>
test<T>::test()
{
;
}
//main.cpp#include <iostream>
#include "test.h"
using namespace std;
int main()
{
test <int> t;
return 0;
}
编译的时候提示undefined reference to `test<int>::test()'|但是把 test.cpp的内容剪切到test.h里面的时候 编译就通过了如果不使用容器类也不会有问题的 求解
试试在VS2008,2010使用C++制定的模板分离编译模式export关键字
2L的意思是 #include "test.cpp" ??