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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:44:13+00:00 2026-05-18T00:44:13+00:00

Spoiler alert: Maybe a stupid question. :) #include <iostream> using namespace std; class Base

  • 0

Spoiler alert: Maybe a stupid question. 🙂

#include <iostream>

using namespace std;

class Base
{
    public:
        virtual void YourMethod(int) const = 0;
};

class Intermediate : private Base
{
    public:
        virtual void YourMethod(int i) const
        {
            cout << "Calling from Intermediate" << i << "\n";
        }
};

class Derived : private Intermediate, public Base
{
    public:
        void YourMethod(int i) const
        {
            cout << "Calling from Derived : " << i << "\n";
        }
};

int main()
{
}

Can someone Explain to me why this throws the compiler warning:

main.cpp:21: warning: direct base ‘Base’ inaccessible in ‘Derived’ due to ambiguity

Now, I understand that there is no way this code will work. I want to know why. Base is private to Intermediate so it should not be visible to Derived through Intermediate. So where does the ambiguity come from? In constructor?

  • 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-18T00:44:14+00:00Added an answer on May 18, 2026 at 12:44 am

    This has nothing to do with overriding functions. It has to do with conversions. It really doesn’t have to do with accessibility (i.e “private” or such) directly either. Here is a simpler example

    struct A { int a; };
    struct B : A { };
    struct C : B, A { }; // direct A can't be referred to!
    

    You can refer to the indirect A object by first converting to B and then to A:

    B *b = &somec;
    A *a = b;
    

    You cannot do such with the direct A object. If you try to directly convert to A, it will have two possibilities. It follows that it is impossible to refer to the non-static data members of the direct A object given a Derived object.

    Notice that accessibility is orthogonal to visibility. Something can be accessible even tho it’s not visible (for example by refering to it by a qualified name), and something can be visible even though it’s not accessible. Even if all the above derivations would be declared private, the problem would still show up: Access is checked last – it won’t influence name lookup or conversion rules.

    Also, anyone can cast to an unambiguous private base class with defined behavior (the C++ Standard makes an exception for this) using a C-style cast, even if normally access wouldn’t be granted to do so. And then there are still friends and the class itself that could freely convert.

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

Sidebar

Related Questions

I added a spoiler class in CSS to use for, well, spoilers. Text is
I've been somewhat spoiled using Eclipse and java. I started using vim to do
I have been spoiled by either using sql server to store data, or using
Super-beginner easy points ruby question. I'm trying to learn some ruby by programming the
There is another recent Project Euler question but I think this is a bit
I've been using ReadDirectoryChangesW to monitor a particular portion of the file system. It
Spoiler: I am an absolute beginner to C. I quickly threw threw together this
spoiler : This is just another Lucene vs Sphinx vs whatever, I saw that
I've been spoiled by the SqlDataSource, but I'm in a scenario where I can't
I am accessing a service and I get returned an object in the form

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.