Home > expected class > error conversion to inaccessible base class is not allowed

Error Conversion To Inaccessible Base Class Is Not Allowed

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and expected class member or base class name policies of this site About Us Learn more about Stack Overflow the

Expected Class Name Before Token Inheritance

company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags expected class-name before ‘ ’ token c++ inheritance Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes

Can Protected Class Be Inherited

a minute: Sign up C++ inheritance - inaccessible base? up vote 75 down vote favorite 10 I seem to be unable to use a base class as a function parameter, have I messed up my inheritance? I have the following in my main: int some_ftn(Foo *f) { /* some code */ }; Bar b; some_ftn(&b); And the class Bar inheriting from c++ inheritance private Foo in such a way: class Bar : Foo { public: Bar(); //snip private: //snip }; Should this not work? I don't seem to be able to make that call in my main function c++ inheritance share|improve this question edited Nov 27 '11 at 8:30 aaaidan 3,39933875 asked Jan 31 '11 at 2:19 bandai 395146 add a comment| 2 Answers 2 active oldest votes up vote 139 down vote accepted You have to do this: class Bar : public Foo { // ... } The default inheritance type of a class in C++ is private, so any public and protected members from the base class are limited to private. struct inheritance on the other hand is public by default. share|improve this answer edited Jul 17 '15 at 15:06 Barry 101k10129274 answered Jan 31 '11 at 2:22 Andrew Noyes 2,99111013 add a comment| Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example). Subscribed! Success! Please click the link in the confirmation email to activat

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business

C++ Public Inheritance Private Members

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation

C++ Public Vs Private Vs Protected

Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like error: is an inaccessible base of you, helping each other. Join them; it only takes a minute: Sign up Inheritance: 'A' is an inaccessible base of 'B' up vote 49 down vote favorite 11 $ cat inheritance.cpp #include using namespace std; class http://stackoverflow.com/questions/4847100/c-inheritance-inaccessible-base A { }; class B : private A { }; int main() { A* ab = new B; } $ $ g++ inheritance.cpp inheritance.cpp: In function 'int main()': inheritance.cpp:9: error: 'A' is an inaccessible base of 'B' $ I just do not understand this error. As I understand, and as this tutorial confirms, private inheritance should only change how the members of class B are visible to the outside world. I think the private specifier http://stackoverflow.com/questions/9661936/inheritance-a-is-an-inaccessible-base-of-b is doing more than just change visibility of class B members here. What do I get this error and what does it mean? Basically what is wrong with allowing this type of code in C++? Looks totally harmless. c++ inheritance share|improve this question asked Mar 12 '12 at 4:55 Lazer 25k66211309 add a comment| 5 Answers 5 active oldest votes up vote 64 down vote accepted By making the inheritance private, you're basically saying that even the fact that B inherits from A (at all) is private -- not accessible/visible to the outside world. Without getting into a long-winded discussion of what would happen if it was allowed, the simple fact is that it's not allowed. If you want to use a pointer to base to refer to an object of derived type, then you're pretty much stuck with using public inheritance. Edit: Since somebody went to the trouble of sending an email to ask for more information about what could happen if this was allowed, I guess I'll elaborate a little on it. The basic problem is that private inheritance is not necessarily intended to follow the Liskov substitution principle. Public inheritance asserts that a derived object can be substituted for an object of the base class, and proper semantics will still result. Private inheritance does not assert that though. The usual de

LearningModern CodeNetworkingOpen SourceStorageToolsDeveloper TypeEmbedded SystemsGame DevMediaTechnical, Enterprise, HPCWebOSAll ToolsAndroid*HTML5Linux*OS X*Windows*ResourcesCode SamplesContact SupportDocumentationFree SoftwareIntel Registration CenterProduct ForumsSDKsResourcesPartner with IntelAcademic ProgramPartner SpotlightBlack Belt DeveloperDeveloper https://software.intel.com/en-us/articles/intel-c-compiler-for-windows-error-conversion-to-inaccessible-base-class-is-not-allowed MeshInnovator ProgramSuccess StoriesLearnBlogBusiness TipsEventsVideosSupportContact SupportDeveloper EvangelistsFAQsForums Search form Search https://bytes.com/topic/c/answers/650523-inaccessible-base-despite-public-inheritance Intel® C++ Compiler for Windows* - Error: conversion to inaccessible base class is not allowed By mark-sabahi (Intel), Added July 2, 2009 Translating...TranslateChinese SimplifiedChinese TraditionalEnglishFrenchGermanItalianPortugueseRussianSpanishTurkish This is a computer translation of the original content. expected class It is provided for general information only and should not be relied upon as complete or accurate. Share Tweet Share Visual C++* .NET 2003 or Visual C++ 2005 will not compile the following code. For compatibility reason, Intel® C++ Compiler will emit error conversion to a compile error when /Qvc7.1 or /Qvc8 is specified. The compiler will compile the code with a warning when the /Qvc6 option is specified. If /Qvc is not explicitly specified, the one provided in ia32 For more complete information about compiler optimizations, see our Optimization Notice. Categories: Intel® C++ Compiler Intel® Parallel Studio XE Composer Edition C/C++ Microsoft Windows* (XP, Vista, 7) ForumsTools Add a Comment Top (For technical discussions visit our developer forums. For site or software product issues contact support.) Please sign in to add a comment. Not a member? Join today Support Terms of Use *Trademarks Privacy Cookies Publications Intel® Developer Zone Newsletter Intel® Parallel Universe Magazine Look for us on: Facebook Twitter Google+ LinkedIn YouTube English 简体中文 Русский Español Português Rate Us

Post your question and get tips & solutions from a community of 418,509 IT Pros & Developers. It's quick & easy. inaccessible base despite public inheritance P: n/a Stefan Weber Hi, I have the following header file (named test.h): class Foo { public: Foo(void) {} virtual ~Foo(void) {} }; class Bar : public Foo { public: Bar(void) {} virtual ~Bar(void) {} }; with a very simple cpp file: #include "test.h" int main() { Foo* f = new Bar(); } This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an error: bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar Acutally, I know that this error message occurs when doing something like "class Bar : private Foo" (i.e. inherit the code but withouth polymorphism). But I obviously declared to use public inheritance. Does anybody see the problem? Thanks, Stefan May 22 '07 #1 Post Reply Share this Question 9 Replies P: n/a Victor Bazarov Stefan Weber wrote: I have the following header file (named test.h): class Foo { public: Foo(void) {} virtual ~Foo(void) {} }; class Bar : public Foo { public: Bar(void) {} virtual ~Bar(void) {} }; with a very simple cpp file: #include "test.h" int main() { Foo* f = new Bar(); } This compiles with Visual Studio 2005, but with g++ 4.1.1 I get an error: bash-3.00$ test.cpp:4: error: Foo is an inaccessible base of Bar Acutally, I know that this error message occurs when doing something like "class Bar : private Foo" (i.e. inherit the code but withouth polymorphism). But I obviously declared to use public inheritance. Does anybody see the problem? The only /potential/ problem is the name of the header file. Put the code you posted in the same cpp file and compile it again (comment out 'with a very...' and the '#include'). If it compiles, the problem isn't in the code. If it doesn't, you're SOL. Get a better compiler. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask May 22 '07 #2 P: n/a Howard "Stefan Weber"

 

Related content

c# error 2 expected class delegate enum interface or struct

C Error Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Delegate Enum Interface Or Struct Void a li li a href How To Solve Expected Class Delegate Enum Interface Or Struct a li li a href Error Type Or Namespace Definition Or End-of-file Expected a li ul td tr tbody table p here for relatedl a quick overview of the site Help error expected class delegate enum interface or struct Center Detailed answers to any questions you might have Meta expected class delegate enum

c# error cs1518 expected class delegate enum interface or struct

C Error Cs Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href How To Solve Expected Class Delegate Enum Interface Or Struct a li li a href Error Type Or Namespace Definition Or End Of File Expected a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of error expected class delegate enum interface or struct c this site About Us Learn more about

compiler error message cs1518

Compiler Error Message Cs table id toc tbody tr td div id toctitle Contents div ul li a href C Cs a li li a href Expected Class Delegate Enum Interface Or Struct C a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to relatedl any questions you might have Meta Discuss the workings p h id C Cs p and policies of this site About Us Learn more about Stack Overflow error cs expected class delegate enum interface or struct the company Business Learn more about hiring developers

error 1 expected class delegate enum interface or struct

Error Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Delegate Enum Interface Or Struct In Mvc a li li a href Expected Class Delegate Enum Interface Or Struct cs a li li a href How To Solve Expected Class Delegate Enum Interface Or Struct a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn relatedl more

error 2 expected class delegate enum interface or struct

Error Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href List Expected Class Delegate Enum Interface Or Struct a li li a href Expected Class Delegate Enum Interface Or Struct cs a li li a href Type Or Namespace Definition Or End-of-file Expected a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site relatedl About Us Learn more about Stack Overflow the

error cs1518 expected class

Error Cs Expected Class p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of expected class delegate enum interface or struct c this site About Us Learn more about Stack Overflow the company Business Learn cs error more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a

error cs1518 expected class delegate enum interface or struct

Error Cs Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Delegate Enum Interface Or Struct Void a li li a href Expected Class Delegate Enum Interface Or Struct In Mvc a li li a href Error Type Or Namespace Definition Or End Of File Expected a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings relatedl and policies of this site About Us Learn

error expected either a definition for a tag name

Error Expected Either A Definition For A Tag Name table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Name C a li li a href Expected Class Name Before Token Qt a li li a href Base Class Has Incomplete Type a li li a href Undefined Reference To Vtable a li ul td tr tbody table p p p basic information about a student and their test relatedl grades I need to have the user determine invalid use of incomplete type c the number of structures to be defined I know

expected class delegate enum interface or struct error

Expected Class Delegate Enum Interface Or Struct Error table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Delegate Enum Interface Or Struct Void a li li a href How To Solve Expected Class Delegate Enum Interface Or Struct a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the relatedl workings and policies of this site About Us Learn more expected class delegate enum interface or struct in mvc about Stack Overflow the company

inline script error expected class delegate enum interface or struct

Inline Script Error Expected Class Delegate Enum Interface Or Struct table id toc tbody tr td div id toctitle Contents div ul li a href Expected Class Delegate Enum Interface Or Struct In Mvc a li li a href Cs Expected Class Delegate Enum Interface Or Struct a li li a href Identifier Expected C a li li a href C Enum a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed relatedl answers to any questions you might have Meta expected class delegate enum interface or struct void Discuss the