Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
see Subject title. I'm not entirely sure what this snippet of code entails. Why would we do this when we could simply instantiate the class that holds ConstructorA in the game's main class?

Here is the tutorial code I am basing this off of.

Audio Example[^]

In section 1.
Posted
Updated 23-Mar-11 8:55am
v3

That's the constructor of the derived class 'constructorA' with parameter of type 'Game' which in turn calls,in its initializer list, the base class ('base') constructor with same argument type, passing it its argument.

Such a mechanism is often useful.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 23-Mar-11 14:57pm    
Three answers at the same time. My 5.
--SA
Wendelius 23-Mar-11 16:26pm    
Have to ask, is it just coincidence that all three answers also all have three votes :)
It calls the base classes constructor with the parameter passed to the derived class constructor. The advantage is for example if you have multiple derived classes and you want to use same constructor in each so you can define the logic in the base class.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Mar-11 14:57pm    
Three answers at the same time. My 5.
--SA
CPallini 23-Mar-11 16:09pm    
5.
It means that a constructor of a class uses a constructor of its base class to pass a variable of the type Game before further initialization.

—SA
 
Share this answer
 
Comments
Wendelius 23-Mar-11 15:01pm    
Quite a coincidence :) +5
Sergey Alexandrovich Kryukov 23-Mar-11 16:40pm    
It is. Thank you for the vote.
--SA
CPallini 23-Mar-11 16:10pm    
5.
Sergey Alexandrovich Kryukov 23-Mar-11 16:40pm    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900