使用指针模板时链接器错误

时间:2016-07-21 17:13:20

标签: c++ templates pointers linker-errors

我在尝试编译代码时遇到链接器错误

1>main.obj : error LNK2019: unresolved external symbol "public: __cdecl Grid<class Grid<class PointData *> *>::Grid<class Grid<class PointData *> *>(struct glm::tvec3<float,0>,int,float)" (??0?$Grid@PEAV?$Grid@PEAVPointData@@@@@@QEAA@U?$tvec3@M$0A@@glm@@HM@Z) referenced in function "void __cdecl `dynamic initializer for 'grid''(void)" (??__Egrid@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol "public: __cdecl Grid<class Grid<class PointData *> *>::~Grid<class Grid<class PointData *> *>(void)" (??1?$Grid@PEAV?$Grid@PEAVPointData@@@@@@QEAA@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'grid''(void)" (??__Fgrid@@YAXXZ)

这是在main.cpp中引起它的行

Grid<Grid<PointData*>*> grid(glm::vec3(0, 0, 0), 1000, 10000);

即使我已经实现了一个带指针特化的模板类,我仍然会收到错误

template<class T>
class Grid
{...}

template<class T>
class Grid<T*>
{...}



template<class T>
Grid<T>::Grid(glm::vec3 origin, int resolution, float size)
{
    grid = new T*[size*size*size];
    this.origin = origin;
    this.size = size;
    this.gresolution = resolution;
    this.cell_size = size / resolution;
}

template<class T>
Grid<T*>::Grid(glm::vec3 origin, int resolution, float size)
{
    grid = new T*[size*size*size];
    this.origin = origin;
    this.size = size;
    this.gresolution = resolution;
    this.cell_size = size / resolution;
}

我在这里做错了什么? 提前谢谢!

0 个答案:

没有答案