【发布时间】:2012-03-11 02:29:47
【问题描述】:
在创建模板类的实例时,我无法理解为什么会得到一个未解析的外部符号。
导致链接器错误的行是下面对 new 的调用:
Vbo<CustomVertex>* m_pVbo;
...
m_pVbo = new Vbo<CustomVertex> (
geometry.VertCount(),
geometry.Vertices(),
geometry.IndexCount(),
geometry.Indices()
);
// nb: geometry.Vertices return type is CustomVertex**
Vbo类的定义如下:
template <typename T>
class Vbo : public glex
{
public:
Vbo();
Vbo( int nNumVerts, T** ppVertices, int nNumIndices, DWORD* pIndices );
Vbo( const Vbo<T> & rhs ); // copy
Vbo<T> & operator=( const Vbo<T> & rhs ); // assignment
~Vbo();
...
}
以及Vbo构造函数的实现:
template <typename T>
Vbo<T>::Vbo( int nNumVerts, T** ppVertices, int nNumIndices, DWORD* pIndices ) :
m_bInitialized ( false ),
m_nVboId ( 0 ),
m_nVboIdIndex ( 0 ),
m_nNumVertices ( nNumVerts ),
m_nNumIndices ( nNumIndices ),
m_ppVertices ( ppVertices ),
m_pIndices ( pIndices )
{
glex::Load();
Initialize();
}
最后,来自链接器的投诉:
1>Actor.obj : error LNK2019: unresolved external symbol "public: __thiscall Vbo::Vbo(int,class CustomVertex * *,int,unsigned long *)" (??0?$Vbo@VCustomVertex@@@ @QAE@HPAPAVCustomVertex@@HPAK@Z) 在函数 "private: bool __thiscall Actor::InitializeGeometry(class IGeometry &)" (?InitializeGeometry@Actor@@AAE_NAAVIGeometry@@@Z) 中引用 1>C:\cuprofen\Debug\Cuprofen.exe : 致命错误 LNK1120: 1 unresolved externals
有人能看出我的疏忽吗?
【问题讨论】:
标签: c++ templates linker-errors