?
Solved

inheritance Q.

Posted on 1998-11-09
2
Medium Priority
?
212 Views
Last Modified: 2010-04-02
Hi Everyone,
      I have a question in reference to inheritance. I understand what constructors and destructors are for and what they do, but why cant the constructors/destructors be inherited with the public and (if any) protected members?

Thanx

Windy
0
Comment
Question by:windywizrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 80 total points
ID: 1177357
They are inherited in a sense.  The constructors for the derived class call the constuctors for the base class.  But the derived class needs its own constructors, because they have additional construction do to.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177358
for example,

class Base
{
  int BaseInt;
public:
   Base(int i) : BaseInt(i) {} ;
};

class Derived : public Base
{
   int DerivedInt;
public:
   Derived(int BI,int DI) : Base(BI),DerivedInt(DI) {};
};

As you can see the derived class calls the base class's constructor to perform the initialization of the BaseInt member, but then it has its own initialization (of DerivedInt) to do.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  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 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 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.
Suggested Courses

777 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