Noah Roberts wrote:
[SNIP]
Methods are actions you may request that an object carry out. You
invoke 'methods' by passing 'messages'; methods are implementations of
messages. This is basic OO terminology that you learn in any
introductory text.
That is the meaning of method in OO. What is the meaning of method in C++?
The problem with C++ is that when you pass a message to an object it
is not necissarily the one that carries out the action even if it
has overridden its parent's methods. This is only guaranteed if
the method is declaired virtual in *all* parents.
That is one interesting issue. The other is that in C++ freestanding
functions (due to ADL and operator overloading) may very well be considered
part of a class types interface.
I suppose this is why some people would consider only
virtual 'functions' to be methods and why
others would object to a "member function" being called a method at
all.
And this is already a source for confusion.
This is also one of the reasons I find C++ does not quite
apply the OO paradigm (which can be a strength at times).
C++ is multiparadigm.
There is also the fact that all C++ "member functions" eventually get
altered to in fact be functions that accept class structs as
arguments. I myself don't believe this should have an impact on our
terminology as it is an implementation detail that the programmer
never really sees.
Unless he starts to do tricks, like calling a member directly from C or
assembly. I saw that being done in an allegedly portable system.
"Why?
The this pointer is the first argument, everybody knows!" Nice parallel to
stating that method has a well defined meaning in C++.
In other OO languages the term method is used and they also get
altered by the compiler to have a more function like signature.
That is OK. They did include the term method into their vocabulary and
defined its meaning. It is not done for C++.
For example Objective-C works this way (many even just preprocess
into C) but we use OO terms not procedural terms.
Does nto have much to do with why it is wrong in C++. For example in
English fast is an OK word. The same word in Hungarian means "the private
parts of a man". So does that mean we should bad the word from English?
Nope. Does that mean we should not use it in Hungarian? Only if you don't
want to get into trouble. But unfortunately (and not talking about yuou
here Noah) some people problems with the sizeof(privates) and so they spend
their time by trolling here and show up contiguous series of knee-jerk
reactions.
In my opinion the *only* reason to call a method "member function" is
because it is what C++ programmer terminology uses;
Method is an operation supported by a classes interface. Therefore method
and member function are not interchangeable. In C++ (using the OO
terminology) freestanding operator functions found by the argument dependent
name lookup are part of the interface provided by the object. And they are
not member functions. For one.
and of course because there are some who will pretend
not to know what you mean, go off on some rant,
and may never answer the question.
Really? How about they *don't* know what do you mean? Or they do, and give
you the answer which is *wrong* for you, because they do NOT understand the
word the same way as you do? Remember the thread where the greenhorn asked
"what methods does the C++ compiler automatically generate for us". Picking
up the *only* closest-thing-toi official-but-still-far-from-it note as a
defintion - where Bjarne Stroustrup that some peoplecall *virtual* member
functions methods - the answer is *NONE*. Not one method is generated.
The term "function" is really not an OO concept and,
in my opinion, it is a mistake to use it as such.
Sure. So don't use it in OO. Here we discuss the C++ language, not OO.