我试图确保一个模块只加载一次,但是当我按照我的方式执行时,编译器会吐出“对我的两个静态类变量的未定义引用: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;
}
任何想法为什么它说对两个变量(实例和模块)的未定义引用?