我正在创建一个DLL
in C++
using Visual Studio 2013
on Windows 8.1 Update 1
。有一个名为的类XMLData
,它有一个名为 的公共成员函数getAttribute
。
XMLData.h
namespace DDGL
{
class DLL_EXPORTED XMLData
{
...
// const char* is used to avoid problems with trying to pass an
// std::string over DLL boundaries
template <typename Type> Type getAttribute (const char* attribute) const;
...
};
}
在 DLL 中,每次使用都会按照您的预期进行实例化并且工作正常。
但是,在应用程序中,我当然会得到未<typename Type>
在 DLL 中使用的未定义引用。
因此,我尝试使用显式模板实例化(如果有的话,我宁愿不将实现放在标题中,以便进行学习练习):
XMLData.cpp
namespace DDGL
{
...
// getAttribute definition
...
template float XMLData::getAttribute(const char* attribute) const;
...
}
但是,我仍然在使用 DLL 的应用程序中得到一个未解析的外部:
输出
error LNK2019: unresolved external symbol "public: float __thiscall DDGL::XMLData::getAttribute<float>(char const *)const " (??$getAttribute@M@XMLData@DDGL@@QBEMPBD@Z) referenced in function "class std::shared_ptr<class DDGL::IGameObject> __cdecl SimpleExplodingRocketDeserialiser(class DDGL::XMLData)" (?SimpleExplodingRocketDeserialiser@@YA?AV?$shared_ptr@VIGameObject@DDGL@@@std@@VXMLData@DDGL@@@Z)
DLL_EXPORTED
#ifdef DDGL_DLL_BUILDING
#define DLL_EXPORTED __declspec(dllexport)
#else
#define DLL_EXPORTED __declspec(dllimport)
#endif
我哪里错了?