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 9227151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:59:55+00:00 2026-06-18T04:59:55+00:00

I cannot find this question even being asked anywhere…so that makes me believe i’m

  • 0

I cannot find this question even being asked anywhere…so that makes me believe i’m doing something very wrong here…

Lets say I have a base class, A, with a constructor that takes in int parameter.
In my derived class, B, I wish to invoke that constructor but also initialize a member reference passed in B’s constructor. How can i do this? I cannot find the syntax to add an initialization list if I call the base class constructor. Is this possible?

Lets say I have:

Class Object
{
   Object(){}
}

Class A
{
   A(int number) : m_number(number){}

public:
   int m_number;
}

Now, how would I initialize m_obj if i wish to call the non-default constructor of A?

e.g.

Class B : Class A
{
   B(int number, const Object& objRef) : A(number)
   {
       m_obj = objRef; //error, : must be initialized in constructor base/member  
                       // initializer list...but I cannot access an initializer list!!
   }

private: 
   const Object& m_obj;
}

as I said, my intent is probably all wrong here, but if it’s valid, I cannot find any syntax examples on google..

go easy on me…:)

  • 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-18T04:59:56+00:00Added an answer on June 18, 2026 at 4:59 am

    In the constructor’s initialization-list:

    B(int number, const Object& objRef) : A(number), m_obj(objRef)
    {}
    

    (Note, this is nothing to do with this being a subclass. You always need to use the initialization list in order to initialize a member variable that’s a reference.)

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

Sidebar

Related Questions

I'm sure this question is asked a lot but I cannot find an answer
I researched this question for days and cannot seem to find an option I
This probably is a dummy question but I cannot find a clear indication. I
This is but a curious question. I cannot find any useful links from Google
This might be a dummy question, but I cannot find any clue in all
Ok this is a homework questions, but I cannot find the answer anywhere, not
After having checked extensively for an answer to this question, I still cannot find
I have been searching for an answer to this question but cannot find anything
Here is the reason why this question was being asked: www.devplusplus.com/Tests/CSharp/Hello_World . While similar
This seems like a common CSS question, but for some reason I cannot find

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.