调用模板ctor时未解析的外部符号
Unresolved external symbol when invoking a template ctor
我很难理解为什么在创建模板类的实例时会得到未解析的外部符号。
导致链接器错误的行是对以下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:错误LNK2019:未解析的外部符号"public:__thiscall Vbo::Vbo(int,class CustomVertex**,int,unsigned long*)"(??0$Vbo@VCustomVertex@@@@QAE@HPAPAVCustomVertex@@HPAK@Z)在函数"private:boll__thiscall Actor::InitializeGeometry(class IGeometry&)"中引用(?InitializeGeometry@Actor@@AAE_NAAVI几何@@@Z)1> C:\cupofen\Debug\cuprofen.exe:致命错误LNK1120:1个未解析的外部
有人能发现我的疏忽吗?
Vbo
构造函数在哪里定义?我猜它在.cpp或.cc文件中,而不是头文件中。模板函数定义需要在头中(或者可以使用更奇特的特性,如显式模板实例化)。这是因为模板函数只有在使用时才被理解为实际代码,并且我假设您的使用与您的定义不在同一个翻译单元中。
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector