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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:54:30+00:00 2026-06-16T02:54:30+00:00

Why is base inaccessible to deriv inside deriv ? The program compiles with class

  • 0

Why is base inaccessible to deriv inside deriv? The program compiles with class deriv : public base.

#include <cstdio>

class base
{
};

class deriv : base
{
  public:
  void f(deriv, int){printf("deriv::f(deriv, int)\n");}
  void f(base){printf("deriv::f(base)\n");}
};

int main()
{
  deriv d;
  d.f(d);
}

17: error: ‘base’ is an inaccessible base of ‘deriv’
17: error:   initializing argument 1 of ‘void deriv::f(base)’

Because two people got it wrong already, I will ask in bold: why does base need to be publicly inherited? It is accessed from within deriv only.

  • 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-16T02:54:31+00:00Added an answer on June 16, 2026 at 2:54 am

    You seem to be incorrectly assuming that conversion from deriv to base when calling deriv::f(base) occurs “inside deriv” and thus has to be accessible. This is not the case. When you call a function, all conversions necessary for initializing function’s arguments occur in the caller’s context. They are not “inside derive“. They happen in the “outside world”. And in your case the “outside world” has no access to deriv-to-base conversion.

    In your specific case it is main that is trying to convert deriv to base. And main cannot do it since it has no access to the private base of deriv. Just to experiment you can declare int main() as a friend of deriv and the code will compile.

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

Sidebar

Related Questions

Here is my code - #include<iostream> using namespace std; class base { public: void
// Base Class class Base { public: void RegisterWithServer(); // some more functions protected:
class Base { public: Base(){} Base(int k):a(k) { } int a; }; class X:virtual
class Base{ //... public: int get()const{ // const // Do something. } int get(int
Suppose I have a base and derived class: class Base { public: virtual void
class Base { public: virtual void foo() {} }; class Derived: public Base {
class Base { public: void foo(){} }; class Derived : public Base { private:
class Base { public void add() { System.out.println(Base ADD); } void subtract() { throw
class base { public: int foo(); int foo(int a); int foo(char* b); int doSomething(int);
class Base { protected: int data; public: virtual int getData() { return data; }

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.