Solved

inheritance Q.

Posted on 1998-11-09
2
208 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
  • 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

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
cb: unreferenced local variable 11 72
Implementing a ResolveEventHandler in C++ 13 116
is twain_32.dll cmpatible with windows 10 ? 10 127
How to gracefully close the c++ 11 thread? 3 83
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…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

895 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

12 Experts available now in Live!

Get 1:1 Help Now