1.声明部分
//point.h
#ifndef _POINT_
#define _POINT_
template<class Elem> class Point
{
public:
Point(Elem);
}
;
#endif
2.实现部分
//point.cpp
#include "point.h"
#include <iostream>
using namespace std;
template<class Elem> Point<Elem>::Point(Elem e)
{
cout << e << endl;
}
3.主程序部分
//main.cpp
#include "point.h" //出错的地方
#include <iostream>
using namespace std;
void main()
{
Point<int> p(10);
}
编译的时候出现错误:
mainTest.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Point<int>::Point<int>(int)" (??0?$Point@H@@QAE@H@Z),该符号在函数 _main 中被引用