473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Distinction between a method and a member function

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
20 8348
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
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
"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
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
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
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
llewelly wrote:
In C++ many operation should not be member functions,
e.g. operators like +, *, ==, and so on.


Nonsense!

Jul 19 '05 #8
"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

"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

"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
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
"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

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

"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
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
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
3427
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
37
4946
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
5
6552
by: Aakash Joshi | last post by:
is there any way we can access private member function of a class from outside. i know we can access private member data using void pointer
3
1700
by: Gregory Bond | last post by:
I'm building a class hierarchy that needs to keep as a class variable a reference to a (non-member) function, so that different subclasses can use different generator functions. But it seems...
7
3006
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class...
11
2262
by: Enquiries, Hopkins Research | last post by:
Hi all I have a conundrum that is puzzling me. I have a large codebase in C that I am converting to C++ as fast as possible (i.e. slowly because I keep learning new idioms and stumbling with...
8
3325
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
6
10539
by: Carlos Martinez | last post by:
Hi all: I have a conceptual doubt. Reading several books, I read the terms method and member function. Are they the same or what is the different meaning? Thanks in advance.
16
3939
by: PengYu.UT | last post by:
Hi, I want to partial specialize the member function doit. But it doesn't work. Could you please help me to figure out what is wrong? Thanks, Peng template <typename T> class A {
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.