我想确保一个模块只加载只有一次,但是当我做我的方式,编译器吐出“未定义参考我的两个静态类变量:S静态变量未定义参考
class Text : public Parent
{
private:
static int Instances;
static HMODULE Module;
public:
Text();
Text(Text&& T);
Text(std::wstring T);
~Text();
virtual Text& operator = (Text&& T);
};
Text::Text() : Parent() {}
Text::~Text()
{
if (--Instances == 0)
FreeLibrary(Module); // Only free the module when
// no longer in use by any instances.
}
Text::Text(Text&& T) : Parent(std::move(T)), Module(std::move(T.Module))
Text::Text(std::wstring T) : Parent(T) // Module only loads when
// this constructor is called.
{
if (++Instances == 1)
{
Module = LoadLibrary(_T("Msftedit.dll"));
}
}
Text& Text::operator = (Text&& T)
{
Parent::operator = (std::move(T));
std::swap(T.Module, this->Module);
return *this;
}
任何想法,为什么它说未定义参考两个变量(实例&模块)?
定义和类的实现是在同一个文件中还是在单独的文件?错误消息指向哪里? – gongzhitaao 2013-03-24 02:57:46
它指向包含该类定义的Cpp文件。标题和cpp文件是分开的。不提供行号。 – Brandon 2013-03-24 03:01:58
[未定义的引用静态变量]的可能的重复(http://stackoverflow.com/questions/14331469/undefined-reference-to-static-variable) – jogojapan 2013-05-30 14:37:57