Solved

Inheritance question

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

770 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