Member Intilization Error
Feb 22, 2013 at 4:15am UTC
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef _GAME_H_
#define _GAME_H_
#include <SDL/SDL.h>
//#include "game.cpp"
class game {
public :
game();
bool bisrunning;
void gamerun();
private :
};
game::game() {
bisrunning = true ;
}
#endif
I get:
E:\CodeBlocks\Games\Doom_Shooter\game.h|16|warning: 'game::bisrunning' should be initialized in the member initialization list|
Why do I get this error?
Feb 22, 2013 at 4:23am UTC
It's being strict - what you have is legal but not best practice.
The member initialisation list would be:
1 2 3
game::game() : bisrunning(true )
{
}
Jim
Feb 22, 2013 at 5:39am UTC
Also the code for all the game class member functions should go in game.cpp not in the header file.
Don't be tempted include .cpp files
HTH
Feb 23, 2013 at 12:02am UTC
Thanks got it working. :D
Topic archived. No new replies allowed.