Solved

Remove inherited method?

Posted on 2009-04-11
3
379 Views
Last Modified: 2013-12-14
Hello,

My C++ is a little rusty but I believe that I cannot  mark an inherited virtual method as "ignore" or "remove" or "delete" so it is not available to subclasses.  In the past, I simply "override" the method in the subclass and threw an Exception that indicated that this method was not available to the subclass.  Is there a better way to handle this situation?

Oh!  In case it matters... I am using the latest version of MSVS C++ CLI.

Thanks for your help,
Mike
0
Comment
Question by:mjgardne
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 24123888
>>My C++ is a little rusty but I believe that I cannot  mark an inherited virtual
>>method as "ignore" or "remove" or "delete" so it is not available to
>>subclasses.

Make it 'private'. Methods declared in the 'private' section of a class are not accessible from derived classes.
0
 
LVL 6

Assisted Solution

by:peter41
peter41 earned 100 total points
ID: 24124654
If methods which you want to hide must stay public in base class,
you can leave them 'public' and make 'private' inheritance, for example:
class CBaseClass
{
public:
...
}
class CNewClass : private CBaseClass
{
...
}
 Thus public methods in base class will not stay public in derived class.
0
 

Author Closing Comment

by:mjgardne
ID: 31569237
Geez!  I was lost in the details and missed the obvious!  Thanks, Guys!  I tagged the methods as private, et voila, the subclasses don't see them.
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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
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…

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

17 Experts available now in Live!

Get 1:1 Help Now