c++ - Is this bad code? -


i've been using code style while now, make class has "id" in front of it, place in header, make .cpp file , put class called "idclassnamelocal". make pure virtual functions in abstract header class, make normal virtual functions in .cpp class , have inherit abstract header class.

is bad code design , coding efficiently?

  • i put id(identification) in front of class name prevent redefinition , cleanness.

example:

// player.h // //////////////////////////////////////////////////////////////// class idplayer { public:     virtual ~idplayer(void) {} // destructor      virtual void playerdata(void) = 0;     virtual void controls(void) = 0; }; extern idplayer* idplayer;  // player.cpp // ////////////////////////////////////////////////////////////// class idplayerlocal : public idplayer { public:     idplayer(void) {} // constructor      virtual void playerdata(void);     virtual void controls(void); }; idplayerlocal idplayerlocal; idplayer* idplayer = &idplayerlocal; // class function definitions void idplayerlocal::playerdata(void) {     player.x = 400;     player.y = 500;      player.w = 20;     player.h = 20;      player.velocityx = (float)0.31;     player.velocityy = (float)0.31; }  void idplayerlocal::controls(void) {     if(::maingame) {         if(key_down(0x41)) { //             player.x = player.x - player.velocityx;             if(player.x <= 0)                 player.x = 0;         }         if(key_down(0x44)) { // d             player.x = player.x + player.velocityx;             if(player.x+player.w >= 650)                 player.x = 650 - player.w;         }         if(key_down(0x57)) { // w             player.y = player.y - player.velocityy;             if(player.y <= 0)                 player.y = 0;         }         if(key_down(0x53)) { // s             player.y = player.y + player.velocityy;             if(player.y+player.h >= 570)                 player.y = 570 - player.h;         }         if(key_down(vk_space)) {          }     } }   // core.cpp // ////////////////////////////////////////////////////////////////  // ... // intialized data // idplayer->playerdata();  while(true) {     // ...     // loop data //     idplayer->controls();     // ... } // ... 

as long using same style throughout code no style bad unless unreadable. able go through code without trouble style. consistent throughout project.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -