Solved

Inheritance question

Posted on 1998-07-15
4
189 Views
Last Modified: 2010-04-01
Is there any way for a subclass to access private members in its baseclass directly? Like if they were declared public. But I dont want other classes to have access to them. If I make public functions returning the private members, I havent
achieved anything really, right? It's visible to all other classes, and the subclasses get access to them in the same way as others...
0
Comment
Question by:moonlight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1167833
Declare friend function.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167834
You can declare derived class or some of its functions to be friends as trestan suggested.  

However, depending on your needs you can declare some of the base class's members as "protected" rather than "private".  That is what protected is for.  However if a member is protected, all publically derived classes will have access to it.  Using friend you could give access to some derived classes and not others.  With protected you are giving access to all.
0
 
LVL 3

Author Comment

by:moonlight
ID: 1167835
I'm sorry trestan, but if you had taken the time to explain like nietod, you'd have had 60 more points now, would have been easy points too.
nietod, answer please, and cash in your points.
0
 
LVL 22

Accepted Solution

by:
nietod earned 10 total points
ID: 1167836
Okay.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Embarcadero C++ Builder XE2 TDateTime 8 91
Precision Problem in C++ 7 67
Gaming Software 1 38
How do I get Window Title of all opened process? 4 60
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question