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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:30:49+00:00 2026-06-01T09:30:49+00:00

Code: struct A{ const bool const_some_write_once_flag; A(): const_some_write_once_flag(false) { } }; struct B: public

  • 0

Code:

struct A{
    const bool const_some_write_once_flag;
    A(): const_some_write_once_flag(false) { }
};
struct B: public A{
    B(): const_some_write_once_flag(true) { }
};

the error is: class ‘B’ does not have any field named ‘const_some_write_once_flag’. I believe that it’s because while being in the constructor of B, the object being created is not yet of type A, because the “inherited slice” of A has not yet been initialized.

I’ve tried several workarounds with no luck, and I’ll omit them here. Is there a way to achieve what I’m trying to do?

  • 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-01T09:30:50+00:00Added an answer on June 1, 2026 at 9:30 am

    In its initializer list,B can only initialize its own data members, its direct base classes, and any virtual base classes. const_some_write_once_flag is none of these; it is a data member of A. It can only be initialized by a constructor of A.

    struct A{
        const bool const_some_write_once_flag;
        A(): const_some_write_once_flag(false) { }
    
    protected:
        A(bool flag) : const_some_write_once_flag(flag) { }
    };
    struct B: public A{
        B(): A(true) { }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: template <class T> struct pointer { operator pointer<const T>()
In code: struct Rep { const char* my_data_; Rep* my_left_; Rep* my_right_; Rep(const char*);
Consider the following code: struct Calc { Calc(const Arg1 & arg1, const Arg2 &
Having code: struct B { int* a; B(int value):a(new int(value)) { } B():a(nullptr){} B(const
I use the following code: struct WorkData { std::string name; std::function<void(std::string)> Callback; WorkData(){}; WorkData(const
This is the code: struct comp { bool operator()(Reputation *one, Reputation *two) { if
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
Here's my code: bool func(const MY_STRUCT *const ptr, some_struct *x, int y) { printf(IN:
I am trying to specialize some utility code on const member functions, but have
So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned

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.