C++中模板类声明和实现能否分离?

1.声明部分

//point.h

#ifndef _POINT_
#define _POINT_

template class Point
{
public:
    Point(Elem);
}
;
#endif


2.实现部分

//point.cpp

#include "point.h"
#include 
using namespace std;
template Point::Point(Elem e)
{
    cout << e << endl;
}

3.主程序部分

//main.cpp

#include "point.h"     //出错的地方
#include 
using namespace std;

void main()
{
    Point p(10);
}


编译的时候出现错误:

mainTest.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Point::Point(int)" (??0?$Point@H@@QAE@H@Z),该符号在函数 _main 中被引用

你可能感兴趣的:(C++,C++模板类,C++模板类的声明和实现)