Solved

inheritance Q.

Posted on 1998-11-09
2
210 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 20 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

726 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