By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Distinction between a method and a member function

P: n/a
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about
an object-oriented design and are feeling particularly pretentious, you may
use the terms "message" and "method," but when you get down to discussing a
C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group,
and neither mention the distinction. Quite a few posts in this group do
seem to use the terms interchangably.

Can anyone explain briefly what the difference is?

Tim
Jul 19 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a
On Sun, 31 Aug 2003 11:56:24 +0000 (UTC), Tim Martin <ta***@cam.ac.uk> wrote:
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about
an object-oriented design and are feeling particularly pretentious, you may
use the terms "message" and "method," but when you get down to discussing a
C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group,
and neither mention the distinction. Quite a few posts in this group do
seem to use the terms interchangably.

Can anyone explain briefly what the difference is?


There isn't any. However, in C++ the term is member function. In Java the
term is method. Different language, different lingo.

The C++ standard uses the term member function, and sticking with the
convention used in a domain assists communication.

--
Sam Holden

Jul 19 '05 #2

P: n/a
Tim Martin writes:
I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about an object-oriented design and are feeling particularly pretentious, you may use the terms "message" and "method," but when you get down to discussing a C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group, and neither mention the distinction. Quite a few posts in this group do
seem to use the terms interchangably.

Can anyone explain briefly what the difference is?


As far as I am concerned "method" is Smalltalk jargon and "member function"
is C++ jargon. There is a recent,43 message thread, mostly pointless, on
alt.comp.lang.learn.c-c++. In searching for it I noted a 125 message thread
from a couple years ago. I suspect this was the same tempest in a teapot.
I am using a primitive Microsoft program called Lookout Express so this link
will probably be messed up.

http://www.google.com/groups?hl=en&l...=bi38c9%249dg%
241%40titan.btinternet.com&rnum=1&prev=/groups%3Fq%3Dmember%2Bsmalltalk%2Bgr
oup:alt.comp.lang.learn.c-c%252B%252B%26num%3D20%26hl%3Den%26lr%3Dlang_en%26
ie%3DUTF-8%26sa%3DG%26scoring%3Dd
Jul 19 '05 #3

P: n/a
"Tim Martin" <ta***@cam.ac.uk> wrote in message
news:bi**********@hercules.btinternet.com...
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about an object-oriented design and are feeling particularly pretentious, you may use the terms "message" and "method," but when you get down to discussing a C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group, and neither mention the distinction. Quite a few posts in this group do
seem to use the terms interchangably.

Can anyone explain briefly what the difference is?

Tim


The author appears to be pedantic about some detail that does not really
exist. Member functions are often used when talking about C++, but in
reality they are all interchangeable descriptions*, and convey the notion of
some action on an object. It is, basically a question of terminology.

* Unless perhaps, you are talking about the differences between each
languages' embodiment of the general theme; In that case maybe it's useful
to use different terminology consistently.
Jul 19 '05 #4

P: n/a
osmium wrote:

As far as I am concerned "method" is Smalltalk jargon and "member function"
is C++ jargon. There is a recent,43 message thread, mostly pointless, on
alt.comp.lang.learn.c-c++. In searching for it I noted a 125 message thread
from a couple years ago. I suspect this was the same tempest in a teapot.
I am using a primitive Microsoft program called Lookout Express so this link
will probably be messed up.

http://www.google.com/groups?hl=en&l...=bi38c9%249dg%
241%40titan.btinternet.com&rnum=1&prev=/groups%3Fq%3Dmember%2Bsmalltalk%2Bgr
oup:alt.comp.lang.learn.c-c%252B%252B%26num%3D20%26hl%3Den%26lr%3Dlang_en%26
ie%3DUTF-8%26sa%3DG%26scoring%3Dd


You can shorten those Google links a lot:

http://www.google.com/groups?threadm...btinternet.com

That should do it. Only the "threadm" part is important, or "selm" if
it's a particular post, rather than a complete thread.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5

P: n/a
Tim Martin wrote:
I came across a detail in "C++ Gotchas" by Stephen Dewhurst
that confused me a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods.
When you talk about an object-oriented design
and are feeling particularly pretentious,
you may use the terms "message" and "method"
but when you get down to discussing a C++ implementation
of your design, use the terms "function call" and "member function".'

What he doesn't say is
what the difference between a method and a member function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group,
and neither mention the distinction. Quite a few posts in this group
do seem to use the terms interchangeably.
Can anyone explain briefly what the difference is?


The term *method* is usually reserved for the abstract description.
When the abstract method is implemented,
it is called a procedure, subroutine, function, operator or macro
as is appropriate for the computer programming language in question.
The reference to methods in the context of the Java or Smalltalk
computer programming languages is probably abusive.

Jul 19 '05 #6

P: n/a
Tim Martin <ta***@cam.ac.uk> writes:
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about
an object-oriented design and are feeling particularly pretentious, you may
use the terms "message" and "method," but when you get down to discussing a
C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.

Furthermore, I've looked through the C++ FAQ and the archive of this group,
and neither mention the distinction. Quite a few posts in this group do
seem to use the terms interchangably.

Can anyone explain briefly what the difference is?


Sometimes the term 'method' is used to indicate any operation on an
object. In C++ many operation should not be member functions,
e.g. operators like +, *, ==, and so on.
Jul 19 '05 #7

P: n/a
llewelly wrote:
In C++ many operation should not be member functions,
e.g. operators like +, *, ==, and so on.


Nonsense!

Jul 19 '05 #8

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:3F**************@jpl.nasa.gov...
Tim Martin wrote:
Can anyone explain briefly what the difference is?


The term *method* is usually reserved for the abstract description.
When the abstract method is implemented,
it is called a procedure, subroutine, function, operator or macro
as is appropriate for the computer programming language in question.
The reference to methods in the context of the Java or Smalltalk
computer programming languages is probably abusive.


Nah. What is refered to as a member function in C++ IS a method in Java.
Just a different name.
A simple function is not a member of a class. There is no equivalent in
Java.
It's just different names.
--
Gary
Jul 19 '05 #9

P: n/a

"Tim Martin" <ta***@cam.ac.uk> wrote in message
news:bi**********@hercules.btinternet.com...
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk about an object-oriented design and are feeling particularly pretentious, you may use the terms "message" and "method," but when you get down to discussing a C++ implementation of your design, use the terms "function call" and
"member function."'

What he doesn't say is what the difference between a method and a member
function is.


Frankly, he's the one that sounds a bit pretentious. Assuming you are
writing OO code in C++, then using both the language of OO design and the
language of C++ implementation are valid. It doesn't make sense to be
pedantic and point out every time you make a comment that you're in the "OO
realm" or "C++ realm" at the moment. It's not pretentious at all to say
"message" or "method" when discussing a design implemented in C++. If there
is a difference between "method" and "function" in the context about which
I'm speaking, it would be that "method" is more abstract - in the OO sense -
and "function" is more concrete - in the C++ implementation sense.
Jul 19 '05 #10

P: n/a

"osmium" <r1********@comcast.net> wrote in message
news:bi************@ID-179017.news.uni-berlin.de...
I am using a primitive Microsoft program called Lookout Express so this link will probably be messed up.

http://www.google.com/groups?hl=en&l...=bi38c9%249dg% 241%40titan.btinternet.com&rnum=1&prev=/groups%3Fq%3Dmember%2Bsmalltalk%2Bgr oup:alt.comp.lang.learn.c-c%252B%252B%26num%3D20%26hl%3Den%26lr%3Dlang_en%26 ie%3DUTF-8%26sa%3DG%26scoring%3Dd


Try www.makeashorterlink.com
Jul 19 '05 #11

P: n/a
jeffc wrote:
It's not pretentious at all to say
"message" or "method" when discussing a design implemented in C++.


I think that it is pretentious.

Jul 19 '05 #12

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
llewelly wrote:
In C++ many operation should not be member functions,
e.g. operators like +, *, ==, and so on.


Nonsense!


Problem #0 Uncessary access. For example:

struct my_complex
{
double real()const{return real_;}
double imaginary()const{return imaginary_;}
private:
double real_, imaginary_;
};

With this interface, nonassignment operators need no access, and
therefor should not have it.

Problem #1 Member functions are not compatible with non-member
functions, and the standard C++ library treats member functions as
second class citizens, requiring use of std::mem_fun, or
boost::mem_fn, niether of which correctly handles all cases.

#include<algorithm>

struct my_int
{
my_int():value(0){}
explicit my_int(int value):value(value){}
bool operator>(my_int rhs)const{return value > rhs.value;}
private:
int value;
};

int main()
{
int const size= 10;
my_int a[size];
//... fill a.
std::sort(a, a+size, &my_int::operator>);
}

Does not compile. Rewrite operator> as a non-member:

struct my_int
{
my_int():value(0){}
explicit my_int(int value):value(value){}
friend bool operator>(my_int lhs,my_int rhs){return lhs.value > rhs.value;}
private:
int value;
};

int main()
{
int const size= 10;
my_int a[size];
//... fill a.
std::sort(a, a+size, &operator>); //compiles easily.
}

This example could also be 'fixed' using mem_fun, but others using
binders cannot. Some (but not all!) examples using binders can
be fixed with boost::bind or boost::mem_fn .

Problem #2 Overloading rules do not apply implicit conversions for the
left hand operator.

struct my_int
{
my_int():value(0){}
my_int(int value):value(value){}
my_int operator+(my_int rhs)const{return value + rhs.value;}
private:
int value;
};

int main()
{
my_int a;
int b;
my_int c= a + b; //compiles.
my_int d= b + a; //does not compile.
}

I say it is nonsense to implement operator+ so that a + b compiles but
b + a does not. The work-arounds? (a) do without the implicit
conversion, and (b), implement more overloads of operator+, some
of which *must* be non-members, because the left-hand operand
must be of a type other than my_int.

Problem #3 The oft-posted mistake:

struct my_int
{
my_int operator+(my_int rhs){return value + rhs.value;}
private:
int value;
};

Did you catch it? const, where necessary, more easily remembered, (and
more easily noticed missing) in the parameter list.

There are more problems with member functions, but they are mostly
minor.

Jul 19 '05 #13

P: n/a

I just thought:

a method is like a "function" but without a return value.

a function is like a "method" but with a return value.
void ThisIsAMethod(.....);
long ThisIsAFunction(....)
Greetings,
Howie

Jul 19 '05 #14

P: n/a

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:3F**************@jpl.nasa.gov...
jeffc wrote:
It's not pretentious at all to say
"message" or "method" when discussing a design implemented in C++.


I think that it is pretentious.


Then I guess you think discussing anything in OO design terms rather than
C++ terms is "pretentious"? That's silly.
Jul 19 '05 #15

P: n/a
Howie escribió:
a method is like a "function" but without a return value.


That thing is called "procedure" in languages that makes the difference.

Regards.
Jul 19 '05 #16

P: n/a
Tim Martin wrote:
Hi,

I came across a detail in "C++ Gotchas" by Stephen Dewhurst that
confused me a bit. The author states:

'C++ has no "methods." Java and Smalltalk have methods. When you talk
about an object-oriented design and are feeling particularly
pretentious, you may use the terms "message" and "method," but when
you get down to discussing a C++ implementation of your design, use
the terms "function call" and "member function."'

What he doesn't say is what the difference between a method and a
member function is.

Furthermore, I've looked through the C++ FAQ and the archive of this
group, and neither mention the distinction. Quite a few posts in this
group do seem to use the terms interchangably.

Can anyone explain briefly what the difference is?


The difference is that method is an OO term and there is no well defined
meaning for in when you talk about C++. Some understands it as any member
function. Some others understand it only as virtual member functions. In
fact - if we take the original OO meaning - non-member operator functions
(found by ADL) should also be called methods in C++, since they *are* part
of the classes interface, they just happen to be implemented as a non-member
function for technical reasons.

C++ really has no methods. It is a terminology aspect. Since what methods
mean in a C++ implementation context might be ambiguous it helps if this
term is not used in that context. Of course this is not a law, it is just
common sense: helps to avoid misunderstandings. For example if you ask the
question: what methods does C++ generate automaticly? some might answer:
none. Since while you have meant "member functions" when saying "method"
those answering meant "virtual member functions" when they have read
"methods".

--
WW aka Attila
Jul 19 '05 #17

P: n/a
Howie wrote:
I just thought:

a method is like a "function" but without a return value.


In some languages that would be a 'procedure'. I've never heard it
called a 'method' before.

In any case, C++ has functions. Whether they return a value or not,
whether they are a member or not, they are always called functions.
That's just the way the language has always been described.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #18

P: n/a

"Kevin Goodsell" <us*********************@neverbox.com> wrote in message news:3f560be1@shknews01...
Howie wrote:
I just thought:

a method is like a "function" but without a return value.


In some languages that would be a 'procedure'. I've never heard it
called a 'method' before.

The common computer science definition of a method is an action performed
on an object. Therefore, they are usually implemented in C++ as non-static
member functions, although not all member functions in C++ are used as methods.

Anyhow, the term is outside the C++ language.
Jul 19 '05 #19

P: n/a
Howie <ho****@webb.de> wrote in message news:<b1********************************@4ax.com>. ..
a method is like a "function" but without a return value.


You're probably thinking "subroutine" or "procedure." "method" is most
definitely an OOP term, most properly associated with virtual
functions in C++ (although it is occasionally [perhaps erroneously]
used to describe non-virtual, non-static member functions as well):

<http://www.nightflight.com/foldoc-bin/foldoc.cgi?method>
<http://www.nightflight.com/foldoc-bin/foldoc.cgi?subroutine>

- Shane
Jul 19 '05 #20

P: n/a
I don't know where I first heard this, or if it's even correct, but I had
understood an "operation" to be something that you do to an object, and the
"method" is the particular implementation that gets called when the object
is asked to perform the operation.

For example, you might define Shape as having a Draw() "operation" (defined
as pure virtual), and objects such as Square, Circle and Rectangle would
provide their own "methods" to implement the Draw() operation.

Of course in C++, you declare and/or define operations and methods by
writing "member functions".

To earlier posters, I don't see anything pretentious about using the word
method. Makes perfect sense to me to use it in the context that I provided
above. The implementation of the Draw() operation for the Square uses a
different method to getting the job done than that of the Circle. Square and
Rectangle use very similar methods to implement the Draw operation.

-mark
Jul 19 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.