提问人:Resurrection 提问时间:12/7/2016 最后编辑:Resurrection 更新时间:12/7/2016 访问量:538
模板化方法中使用的嵌套类的未解析外部符号
Unresolved external symbol of nested class used in templated method
问:
我在此类中遇到了一个奇怪的未解决的外部符号错误。我有一个基于 Qt 的 C++ 库,其中是 或 的别名。LIBDATASHARED_EXPORT
__declspec(dllexport)
__declspec(dllimport)
class LIBDATASHARED_EXPORT SaveFile
{
class Index
{
public:
operator bool() const; //<--- defined in cpp
};
public:
template<typename T> load()
{
Index idx;
if(idx) //<--- complains about unresolved symbol...
{
}
}
};
当我在与库链接的另一个项目中使用它时,我得到了关于实例化模板方法的信息。当我在标题中输入定义时,它工作正常。的定义确实与类的其余定义位于同一 .cpp 文件中,因此应在实例化时定义。unresolved external symbol
SaveFile::Index::operator bool() const
SaveFile::Index::operator bool() const
SaveFile::Index::operator bool() const
这里有什么问题,我该如何解决?
答:
1赞
Resurrection
12/7/2016
#1
问题是还必须导出内部类,因此在这种情况下的解决方案是将 添加到内部类中,因为它不是由外部类导出的(外部类本身是导出的)。使用 Dependency Walker 发现。LIBDATASHARED_EXPORT
评论
SaveFile::Index::operator bool() const
operator bool