method Vs function

Mar 4, 2010 at 1:22am
I'm a little (or a lot?) confused as to what the difference is, if they are indeed different, between a method and a function in C++.

When someone says write a method that does this and that is it the same as saying write a function?
Mar 4, 2010 at 1:24am
A method is a "member function" of a class.
Mar 4, 2010 at 1:25am
Functions stand alone and methods are members of a class. That's all. (I personally despise the term method but it's really all the same.)
Mar 4, 2010 at 1:26am
and what is a function?

If you simply say function then it could appear anywhere, including outside of a class?

So a method IS a function but a function NOT NECESSARILY a method?
Mar 4, 2010 at 1:27am
Clear. Thanks!
Mar 4, 2010 at 1:31am
In the most technical of meanings, method != function and function != method, ever.
Mar 4, 2010 at 1:35am
Well,

(method <= function) and function !(function<=method)

where "<=" is a special ordering operator with the definition quite obvious.

This contains more information than (method!=function).
Last edited on Mar 4, 2010 at 1:37am
Mar 4, 2010 at 1:44am
Function: a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code.
Member function (or "method" in OOPese): a function that is a member of a class. The membership gives it special properties global functions don't have, such as being in a different namespace (that of the class), and taking an implicit this parameter (only for non-static member functions).

Member function ⊂ function.
Topic archived. No new replies allowed.