views:

92

answers:

2

I have a binary that has always existed. It has a class C that it has always existed as well. We have to introduce a new method M to the class C but we only want some users to be aware of the existence of such method M.

By removing from the .h file such method, which problem we can introduce? Will such approach be backward compatible?

EDIT: We actually don't care if there's a way to find the method. We just want to make sure that only people knowing what they're doing, use it.

+6  A: 

A safer method would be to simply make a derived class and give that one's .h only to certain people.

Brian R. Bondy
+7  A: 

With most C++ compilers: if the method is virtual you'll be in serious trouble (the vtable will be all messed up); if the method is NOT virtual you shouldn't be (but some smart user will deduce the existence of what you're trying to hide via "security through obscurity" and find ways to use the method you'd rather keep hidden from him -- but that's another story;-).

Alex Martelli
note that there's no guarantee that the class will still work. But yeah, commonly you'll probably get away with it as long as the function is nonvirtual.
jalf
Absolutely no guarantee, as I said ("shouldn't" implies it's unlikely but NOT impossible -- I recall an IBM "direct to SOM" C++ compiler that set private/protected/public stuff in a way almost guaranteed to trip you up if you were trying ANY hanky-pakny!-).
Alex Martelli