Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

functions vs. methods?

40 views
Skip to first unread message

Doug Mika

unread,
May 12, 2015, 2:49:10 PM5/12/15
to
I got the following line from my book:

"ios_base::failure - thrown by the functions and methods in the iostream library."

the question I have is, is there a difference between functions and methods in C++? I always thought they were two words used to describe the same thing!

Melzzzzz

unread,
May 12, 2015, 2:54:52 PM5/12/15
to
methods are member functions. Everybody calls them methods ;)
Message has been deleted

Marcel Mueller

unread,
May 12, 2015, 2:59:38 PM5/12/15
to
There is no real difference. Depending on the language and the personal
flavor the one the other might be preferred. The term method is more
likely used in conjunction with object orientation and member functions,
while free functions are rarely called methods. However, both identify
basically the same thing. There are significantly larger differences
between static and non static member functions.


Marcel

Richard

unread,
May 12, 2015, 3:14:25 PM5/12/15
to
[Please do not mail me a copy of your followup]

Doug Mika <doug...@gmail.com> spake the secret code
<96d29439-79f4-430e...@googlegroups.com> thusly:

>I got the following line from my book:
>
>"ios_base::failure - thrown by the functions and methods in the iostream
>library."
>
>the question I have is, is there a difference between functions and
>methods in C++?

The standard library implements features through functions and classes
with methods.

Functions are not attached to an instance of an object and therefore
do not have a 'this' pointer. Functions can't see internal details of
a class (unless they are friends[*]). Functions are declared outside
of a class, but possibly within a namespace.

Methods are attached to an object and are declared within a class. If
the method is not a static method, then it has access to instance data
of the associated object on which it is invoked. If it is a static
method, then it has access to other static methods and data for that
class.

[*] My advice is to use friend as a last resort. There are times when
it is necessary but most of the time it is used to paper over a hole
in your design.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages