Solved

inheritance Q.

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

9 Experts available now in Live!

Get 1:1 Help Now