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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:44:45+00:00 2026-06-01T23:44:45+00:00

I am getting the following error in C++: error C2614: ‘ChildClass’ : illegal member

  • 0

I am getting the following error in C++:

error C2614: ‘ChildClass’ : illegal member initialization: ‘var1’ is
not a base or member

Class Base 
{
    protected:
    int var1;
public:
    Base()
    {
        var1=0;
    }
}


class Child : public Base
{
    int chld;
    public: 
    Child() : var1(0)
    {
        chld=1;
    }
}

I feel what I have done is as per OO protocol.
Here var1 is a data member of Base class with protected as the access specifier. So It can be inherited and it would become private in child.

Don’t understand why am I getting the error?

  • 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-01T23:44:47+00:00Added an answer on June 1, 2026 at 11:44 pm

    It doesn’t work for the exact reason the error message provides you: you can only use initializer lists with direct members or base classes.

    In your case, you don’t even need to initialize var1, since Base::Base() will be called by Child‘s constructor, which will set var1 to 0.

    If you want a different value, you’ll have to overload Base constructor and call it explicitly:

    class Base 
    {
    protected:
         int var1;
    public:
         Base() : var1(0)
         {
         }
         Base(int x) : var1(x)
         {
         }
    };
    
    class Child:public Base
    {
        int chld;
    public: 
        Child(): Base(42) , chld(1)
        {
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting following error in production but the same is not a repro
We are getting following error when we enter an email address which is not
Hey just getting following error Could not load file or assembly 'Ektron.Cms.Controls, Version=8.0.1.87, Culture=neutral,
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting following error with PHP 5.1.6: Fatal error: Declaration of Tl1Telnet::ExecuteCommand() must
i'm getting following error in my wordpress site, XML Parsing Error: XML or text
I am getting following error when I am trying to get WebResponse using WebResponse
I am getting following error message when using Doctrine ORM in Codeigniter. ( !
I am getting following error in different places like when I am removing an
I am getting following error: error: calling a host function(strcpy) from a __device__/__global__ function(doDecompression)

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.