gpt4 book ai didi

c++ - 链接器错误 : UnResolved External Symbol Issue

转载 作者:行者123 更新时间:2023-11-30 04:21:16 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What does it mean to have an undefined reference to a static member?

目前我有以下代码文件:TestClass.h

class TestClass
{

private:
int i;
static TestClass* TClass;

public:

static TestClass* GetClass()
{
if(TClass==NULL)
{
TClass = new TestClass();
return TClass;
}
else
{
return TClass;
}
}//end method

int Geti()
{
return i;
}

void Seti(int a)
{
i = a;
}
};

现在我的 cpp 文件中有一个方法,在将标题包含为

declspec(dllexport) int __stdcall GetVar()
{

TestClass *TClass = TestClass::GetClass();
return TClass->Geti();
}

我得到的错误是:

Error   8   error LNK2001: unresolved external symbol "private: static class TestClass * TestClass::TClass" (?TClass@TestClass@@0PEAV1@EA)  

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com