我有一个单身课程。我想为结构成员赋值。但是编译器抛出错误为A nonstatic member reference must be relative to a specific object
. 请帮助我,如何解决相同的问题。
class abc{
static abc* m_selfInst;
public:
struct abcd{
int a;
}abcd;
abc* GetInstance();
};
abc* abc::m_selfInst = NULL;
abc* abc::GetInstance()
{
if(m_selfInst == NULL)
{
m_selfInst = new abc();
}
return m_selfInst;
}
int main()
{
abc *ab = abc::GetInstance(); //Error Occurs here
abc::abcd.a = 5; //Error occurs here too
//cout <<ab.abcd.a << "\n";
return 0;
}