Solved

derived class constructor

Posted on 2011-03-18
2
497 Views
Last Modified: 2012-05-11
in C++, does a derived class constructor "automatically" call the base class constructor?
0
Comment
Question by:47pitch
  • 2
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 35168235
Yes - more specifically, the default constructor is called - if you need another ctor, you can call it in the derived class' ctor's initializer list. See also e.g. http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr388.htm ("Initializing base classes and members (C++ only)"): "If you do not explicitly initialize a base class or member that has constructors by calling a constructor, the compiler automatically initializes the base class or member with a default constructor."
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 35168242
Hm, here's a nicer and more thorough explanation: http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/ ("Constructors and initialization of derived classes")
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now