Quantcast
Channel: What are the rules for calling the base class constructor? - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by CR. for What are the rules for calling the base class constructor?

$
0
0

The only way to pass values to a parent constructor is through an initialization list. The initilization list is implemented with a : and then a list of classes and the values to be passed to that classes constructor.

Class2::Class2(string id) : Class1(id) {....}

Also remember that if you have a constructor that takes no parameters on the parent class, it will be called automatically prior to the child constructor executing.


Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>