Solved

derived class constructor

Posted on 2011-03-18
2
500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to fix  a C++ segmentation violation which occurs in a static member function? 22 102
c++ syntax question 9 44
Arduino EDI - Programming language 3 80
Safe conversion? 4 58
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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

910 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

20 Experts available now in Live!

Get 1:1 Help Now