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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:19:11+00:00 2026-05-27T10:19:11+00:00

This is going to sound so basic as to make one think I made

  • 0

This is going to sound so basic as to make one think I made zero effort to find the answer myself, but I swear I did search for about 20 minutes and found no answer.

If a private c++ class member variable (non-static) is a pointer, and it is NOT initialized in the constructor (either through an initialization list or an assignment in the constructor), what will its value be when the class is fully instantiated?

Bonus question: If the answer to the above question is anything other than NULL, and I wish to always initialize a particular member pointer variable to NULL, and I have multiple constructors, do I really have to put an explicit initialization for that pointer in every constructor I write? And if so, how do the pros handle this? Surely nobody actually puts redundant initializers for the same member in all their constructors, do they?

EDIT: I wish I could’ve chosen two answers here. The smart pointers recommended by Bleep Bloop seem to be the elegantest approach, and it got the most up votes. But since I didn’t actually use smart pointers in my work (yet), I chose the most illustrative answer that didn’t use smart pointers as the answer.

  • 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-05-27T10:19:12+00:00Added an answer on May 27, 2026 at 10:19 am

    You’re thinking correctly. If you don’t initialise it, it could be anything.

    So the answer to your question is yet, either initialise it with something, or give it a NULL (or nullptr, in the most recent C++ standard).

    class A
    {
    };
    
    
    class B
    {
    private:
        A* a_;
    
    public:
        B() : a_(NULL) { };
        B(a* a) : a_(a) { };
    };
    

    Our default ctor here makes it NULL (replace with nullptr if needed), the second constructor will initialise it with the value passed (which isn’t guaranteed to be good either!).

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

Sidebar

Related Questions

This is going to sound like a basic question but... How do I use
This is going to sound too silly / too basic - sorry about that,
This is going to sound like a silly question, but I'm still learning C,
Ok this is going to sound strange, but I have inherited an app that
I know this question is going to sound very stupid but here goes nonetheless.
Okay this one may be a bit out from left field, but I'm going
I guess this is going to sound like a pretty basic question to any
This is going to sound super hackish but does anyone know of a way
All right, this one is going to sound very weird and I don't know
I know I am going to sound very noobish for asking this question BUT

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.