H
Howard
modemer said:Thanks for pointing out the key word "virtual". Actually in this question,
virtual or not is not important because my object is to prevent *specific*
function(not all functions) in base class being defined in derived class
The virtual keyword *does* apply to a specific function! (Sure, there is
also virtual inheritance, but that's not what was being pointed out to you.)
Placing the virtual keyword in front of an individual function allows it to
be overridden in derived classes. By *not* placing the virtual keyword in
front of it, you *prevent* overriding that function. You cannot prevent
"hiding" the function, however.
no
matter it's virtual or not as long as there is a way to do, if derived
class
happened defined(we have to believe that programmers have different
understandings about a system), C++ compiler should raise an error, but
unfortunately, nobody could answer this question directly, that means
there
is not this kind of feature in C++.
Correct...there is no such feature. Our point has been that such a feature
is not needed.
You state that "programmers have different understandings about a system".
Well, that's a pretty broad statement, but if you have a programmer working
for you who doesn't know that a function without the keyword "virtual" is
not overrideable, then that programmer needs to go back to school!
not a matter of differences of opinion on how a system works, it's basic
rules of C++, and it's vital that they (and you) understand it.
When I studied C++, I noticed that C++ is trying the best to offer all
possibilities to control how member function of class is handled, like
private/protect/public/virtual/static/overload/override/namingConvention
etc. This is why I am looking for if there is a feature like the one
mentioned in my question. If this feature exists, I think the code or
logic
would be more clear, simple or even easier on bug control, source code
maintain.
It's not neccesarily an error to "hide" a base class function. It may in
fact be exactly what is needed in some specific cases. But as the base
class writer, I can see that you might think it may *never* be useful (for
some specific function, anyways). You may even be right...but you may also
be wrong.
Your idea has been discussed before. As I believe was stated elsewhere, the
thought was a "final" keyword. You can do a search on groups.google.com,
using C++, final, and virtual as search terms, and you should find more info
on the subject.
-Howard