?
Solved

Using Public, Private,a nd Protected to Disallow Access to Certain Member Functions

Posted on 2003-03-29
4
Medium Priority
?
187 Views
Last Modified: 2010-04-02
Hello,

I have a BaseClass with 5 member functions: func1, func2, func3, func4, func5.

I want to create derived classes from BaseClass:
- DerivedClass1 must be able to access all member functions in BaseClass except func5.
- DerivedClass2 must be able to access all member functions in BaseClass except func1.

Is there a way that I can use access specifiers public, protected and private to structure my code in such a way that it restrict access BaseClass functions as indicated?

If anyone knows how I can achieve this result I would appreciate some assistance.  Thank you.
0
Comment
Question by:Invariant
[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
4 Comments
 
LVL 2

Accepted Solution

by:
skyDaemon earned 150 total points
ID: 8232894
You could say:
BaseClass1
Protected:
func2;
func3;
func4;

BaseClass2 : public BaseClass1
Protected:
func1;

BaseClass3: public BaseClass1
Protected:
func5;

DerivedClass1 : public BaseClass2

DerivedClass2  public BaseClass3

0
 
LVL 6

Expert Comment

by:GaryFx
ID: 8236435
Try using friend.

Gary
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8236549
There is probably no way that you can have all the 5 functions in the same base-class and impose those restrictions on the derived classes at the same time. I guess what skyDaemon suggests is a way out.

Mayank.
0
 

Author Comment

by:Invariant
ID: 8240226
Thank you for your assistance and for confirming what I thought to be true, but what I was not certain of until hearing from you all.  As I will use SkyDaemon's approach I have offered SkyDaemon the points...but thanks again to all who offered their comments here.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 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