Encapsulation Extern Break

I am new to C ++ and I am creating a game. I have a class main in which I declare

Game * game; //globally
int main() {
    game = new Game();
    game->show();
}

My class game initiates my game, etc. Now in other classes (player, enemy, etc.) I get variables from the game, such as player health, using

#include<game.h>
extern Game * game;
func::func() {
    game->health->resetHealth();
}

Is this encapsulation / ood paradigm a violation? Is this a bad practice? I see another way to do this for the game.

+4
source share
5 answers

extern . - . extern .
OOP, java, extern. Java / , .

+1

, , . game - , . - , game . - . OOD , " " Game * game. , GameController, Game *. Game * GameController, GameController -, , , . , . , , wrapping (, , ). , - , . . , , Game *, , . - .

+1

, . , , , , . extern , , .

+1

- , , . , , : . , , ( , ).

, - , , :

  • ? ( game , .)
  • , ? (, , , .)
  • ? (, , , !)

, ; , , . A game .

+1

, , . , , , .

, , ( - ), , , , , , .

, . , .

0

All Articles