Eine nichtstatische member-Referenz muss relativ zu einem bestimmten Objekt Singleton-Klasse, C++

Habe ich eine singleton-Klasse. Ich möchte einen Wert zuweisen, der auf ein Struktur-member. Aber der compiler wirft einen Fehler wie A nonstatic member reference must be relative to a specific object.
Bitte helfen Sie mir, wie zu lösen, das gleiche.

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;
}

InformationsquelleAutor Rasmi Ranjan Nayak | 2013-04-22

Schreibe einen Kommentar