[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

derived class constructor

Posted on 2011-03-18
2
Medium Priority
?
514 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

834 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