Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:07:39+00:00 2026-06-17T18:07:39+00:00

I was reading effective C++ and I couldn’t really understand one of the mentioned

  • 0

I was reading effective C++ and I couldn’t really understand one of the mentioned benefit of initialization list.From what I understand is that initialization lists also help to avoid calling of unnecessary default constructors especially when they are not needed. So in order to test that I created a simple code example as such

class base
{
public:

    base()
    {
        std::cout << "Default Constructor called \n";
    }
    base (int i)
    {
        std::cout << "Int constructor called \n";
    }
};

class der : public base
{
private:
    base b;
public:
    der(int i):b(i)
    {
        std::cout << "Derived constructor called \n";
    }
};

void main()
{
    der d(12);
}

No where I assumed that only the int constructor will be called instead both the constructors of the base class are called. Could anyone please clarify this concept.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:07:40+00:00Added an answer on June 17, 2026 at 6:07 pm

    The problem is that you actually have 2 instances of base, one as a member and one as a base. Either change into der(int i):base(i),b(i) or remove the member.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading Effective Java. In a section that talks about using function objects
Reading Effective Java, it seems that there are many advantages, and very few disadvantages,
I have been reading Effective Java by Joshua Bloch and so far it really
I'm reading Effective C++, so I tried to implement the class that prevents construction
I am currently re-reading Effective Java while working at a shop that makes heavy
I am reading effective C++ in Item 5, it mentioned two cases in which
I am reading the chapter on Generics in Effective Java. Help me understand difference
I've been reading through Effective Java by Joshua Bloch. I also develop in PHP
I am reading Bill Wagner's book Effective C# . In Item 32 he is
I was reading Joshua Bloch's Effective Java Programming Language Guide . He explains static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.