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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:38:34+00:00 2026-05-14T03:38:34+00:00

I get a compile error, which I’m slightly confused about. This is on VS2003.

  • 0

I get a compile error, which I’m slightly confused about. This is on VS2003.

error C2248: ‘A::y’ : cannot access protected member declared in class ‘A’

class A
{
public:
  A() : x(0), y(0) {}
protected:
  int x;
  int y;
};

class B : public A
{
public:
  B() : A(), z(0) {}
  B(const A& item) : A(), z(1) { x = item.y;}
private:
  int z;
};

The problem is with x = item.y;

The access is specified as protected. Why doesn’t the constructor of class B have access to A::y?

  • 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-14T03:38:35+00:00Added an answer on May 14, 2026 at 3:38 am

    It’s because of this:

    class base_class
    {
    protected:
        virtual void foo() { std::cout << "base::foo()" << std::endl; }
    };
    
    class A : public base_class
    {
    protected:
        virtual void foo() { std::cout << "A::foo()" << std::endl; }
    };
    
    class B : public base_class
    {
    protected:
        virtual void foo() { std::cout << "B::foo()" << std::endl; }
    
    public:
        void bar(base_class *b) { b->foo(); }
    };
    

    If that were legal, you could do this:

    A a;
    B b;
    b.bar(&a);
    

    And you’d be calling a protected member of A from B, which isn’t allowed.

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

Sidebar

Related Questions

In IntelliJ I get this weird error when I try to compile. Cannot find
I get an error when I compile this code: using System; public struct Vector2
When trying to compile my class I get an error: The constant 'NamespaceName.ClassName.CONST_NAME' cannot
I get a compile error, Cannot implicitly conver type 'System.Collections.ObjectModel.ObservableCollection to ProddataRecsObservable'. An explicit
I get the following error when I try to compile an asp.net site using
When attempting to compile my C# project, I get the following error: 'C:\Documents and
i got a compile error which i do not understand. i have a h/cpp
As already said by the headline, I get a compile error I seem to
Why don't we get compile errors on inline code errors in asp.net mvc views
When I try using a Name=id and\or x:name=id I get a compiler error: The

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.