
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
None | size: 0.88 KB | hits: 17 | expires: Never
static variable re-initializes
static unsigned int masterID=0;
class game{
public:
unsigned int m_id;
unsigned int m_players;
// default constructor
game():m_id(masterID++){
}
// another constructor using a game instance
game(game g): m_id(masterID++){
...
}
// copy constructor
// copy constructor
game(const game &o)
: m_id(o.m_id), m_players(o.m_players)
{ }
// assignment operator
game& operator =(const game o){
m_id = o.m_id;
m_players = o.m_players;
return *this;
};
game g1, g2;
game g3(g2);
class game{
public:
unsigned int m_id;
unsigned int m_players;
static unsigned int masterID; // no initialization!
// default constructor
game():m_id(masterID++){
}
// another constructor
game(unsigned int players): m_id(masterID++), m_players(players){
}
};
game::masterID = 0;