You can have a default and a non default constructor in one as well, something like this. So you can have a default value as well as be able to input a value.
Main Topics
Browse All TopicsIf I have the following scenario, class B and C inherit from A and class D inherit from B and C. If I make class D constructor call the non-default constructors of each of its ancestor.
Statement:
Modify the class calls to the constructors (one at a time), and trace through the constructor calls,
noting any dierences or peculiarities by changing the order of the listing of ancestors
Questions:
1. How do I make class D to call the non-default constructors of each of it's ancestors?
2. What does the statement mean by the class calls to the constructors?
My understanding of question 1 is the following code, is this true:
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>> and if A has a public variable called count, will there be any case in those class call where count is initialized to the same value more than once?
If B and C both were derived from A and D was derived from both C and D, then there are two A objects for a D, B::A and C::A.
[A] [A]
| |
[B] [C]
\ /
[D]
Hence, if A has a public member count, there is a B::A::count and a C::A::count variable which both were initialized with the constructor of A (which was called twice).
Things become different if you derive virtual from A
class B : virtual public A
{
};
class C : virtual public A
{
};
Then you have
[A]
/ \
[B] [C]
\ /
[D]
and only one A object is included in a D. Construction of A happens after construction of B and there is only one count member which can accessed in any D member function by count without scope as long as there is no other count member in B, C, D (what is bad programming).
void D::anyFunc()
{
count++; // is A::count
}
Business Accounts
Answer for Membership
by: FalmarriPosted on 2009-11-03 at 13:54:27ID: 25734216
Yes that is correct. You can also have Ds default constructor call non default constructors
Select allOpen in new window