Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

If you want to continue using the singleton approach, you could benefit from a proper implementation of the singleton design pattern in C++.

Essentially, you define your class as follows:

class myGame {
private:
    static myGame* _instance;
    // Other private members.

public:
    static myGame* Instance();
    // Other public members.
};

And then the Instance function looks like this:

myGame* myGame::Instance() {
    if (!_instance)
        _instance = new myGame();

    return _instance;
}

This way, you can call myGame::Instance() to get your singleton class, and invoke whatever modifier or function you need, from anywhere in your code.

You might also be interested in: http://stackoverflow.com/questions/1008019/c-singleton-design-patternhttps://stackoverflow.com/questions/1008019/c-singleton-design-pattern

If you want to continue using the singleton approach, you could benefit from a proper implementation of the singleton design pattern in C++.

Essentially, you define your class as follows:

class myGame {
private:
    static myGame* _instance;
    // Other private members.

public:
    static myGame* Instance();
    // Other public members.
};

And then the Instance function looks like this:

myGame* myGame::Instance() {
    if (!_instance)
        _instance = new myGame();

    return _instance;
}

This way, you can call myGame::Instance() to get your singleton class, and invoke whatever modifier or function you need, from anywhere in your code.

You might also be interested in: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern

If you want to continue using the singleton approach, you could benefit from a proper implementation of the singleton design pattern in C++.

Essentially, you define your class as follows:

class myGame {
private:
    static myGame* _instance;
    // Other private members.

public:
    static myGame* Instance();
    // Other public members.
};

And then the Instance function looks like this:

myGame* myGame::Instance() {
    if (!_instance)
        _instance = new myGame();

    return _instance;
}

This way, you can call myGame::Instance() to get your singleton class, and invoke whatever modifier or function you need, from anywhere in your code.

You might also be interested in: https://stackoverflow.com/questions/1008019/c-singleton-design-pattern

Source Link
kevintodisco
  • 3.8k
  • 1
  • 18
  • 26

If you want to continue using the singleton approach, you could benefit from a proper implementation of the singleton design pattern in C++.

Essentially, you define your class as follows:

class myGame {
private:
    static myGame* _instance;
    // Other private members.

public:
    static myGame* Instance();
    // Other public members.
};

And then the Instance function looks like this:

myGame* myGame::Instance() {
    if (!_instance)
        _instance = new myGame();

    return _instance;
}

This way, you can call myGame::Instance() to get your singleton class, and invoke whatever modifier or function you need, from anywhere in your code.

You might also be interested in: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern