//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里面的时候 编译就通过了如果不使用容器类也不会有问题的 求解

解决方案 »

  1.   

    这个我以前也遇到了这个问题,估计是IDE的问题吧,后来我没办法,就直接把cpp文件里面的内容拷贝到.h里面运行,就好了,希望高手指点下~~貌似只是这种template类才有的
      

  2.   

    目前VC都不很好的支持模板分离编译模式
    试试在VS2008,2010使用C++制定的模板分离编译模式export关键字
      

  3.   

    用的是codeblock编译器....
    2L的意思是 #include "test.cpp"  ??