Solved

Inheritance question

Posted on 1998-07-15
4
184 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now