Class questions
Is this code
1 2 3 4 5 6
|
Critter::Critter(int hunger) :
m_Hunger(hunger)
{
cout << "A critter has been born!" << endl;
++s_Total;
}
|
same as this?
1 2 3 4 5 6
|
Critter::Critter(int hunger)
{
m_Hunger = hunger;
cout << "A critter has been born!" << endl;
++s_Total;
}
|
And why would you use static data members?
For primitive types yes. For more complex types second version is equivalent to
1 2 3
|
Critter::Critter(int hunger) : m_Hunger() //Default constructing value
{
m_Hunger = hunger; //And instantly assign again.
|
And why would you use static data members? |
If you have some variable which logically belongs to class and is needed to be shared by all instances of it.
http://www.cprogramming.com/tutorial/statickeyword.html
Topic archived. No new replies allowed.