CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: How do you call void foo()

Voters
9. You may not vote on this poll
  • Method

    0 0%
  • Function

    9 100.00%
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    Mar 2007
    Posts
    155

    What void foo() is really? - a Method? OR a Function?

    Dear brothers,
    Hope you all are well
    Code:
    void foo() {}
    I just wonder how should we call the above void foo() correctly -
    Method? or Function?

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by thomus07 View Post
    Method? or Function?
    This shouldn't be a poll. It's "function".

  3. #3
    Join Date
    Nov 2007
    Posts
    74

    Re: What void foo() is really? - a Method? OR a Function?

    Books writing about this is out of date, Mary-go-around story
    I like face-to-face talks about this to see how small or how big I am. That's the way to learn not via net.
    I am looking too for
    1. documents about functions
    2. differences of function and methods
    3. When function is called when method is called

  4. #4
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by Thu View Post
    Books writing about this is out of date, Mary-go-around story
    I like face-to-face talks about this to see how small or how big I am. That's the way to learn not via net.
    I am looking too for
    1. documents about functions
    2. differences of function and methods
    3. When function is called when method is called
    What are you talking about? The C and C++ standards use the ISO 2382 definition of a function. The proper term is "function", period.

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: What void foo() is really? - a Method? OR a Function?

    Functions which belong to class objects may be called methods. Non-class functions are not.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by lindley View Post
    functions which belong to class objects may be called methods. Non-class functions are not.
    +1

  7. #7
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by Arjay View Post
    +1
    I would subscribe to Lindley's definition if it lacked the word "objects", which causes it to disagree with the term "static method". To its credit, however, that definition does underscore an important point to be made concerning functions: non-static member functions (i.e. methods) are incompatible with function pointers of the equivalent signature for the reason that they require an object in order to be invoked.
    - Alon

  8. #8
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: What void foo() is really? - a Method? OR a Function?

    1) As already mentioned, the standard never uses the word "method"
    in this context.

    2) In TC++PL3, Stroustrup states:

    "a virtual member function is sometimes called a method".

  9. #9
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Last edited by _uj; January 5th, 2009 at 12:51 AM.

  10. #10
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: What void foo() is really? - a Method? OR a Function?

    As Philip Nicoletti pointed out, Stroustrup's definition of method in C++ is virtual member function. That Wikipedia article is more general in nature.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  11. #11
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by laserlight View Post
    As Philip Nicoletti pointed out, Stroustrup's definition of method in C++ is virtual member function.
    Well, I don't think C++ actually defines the term "method". But it's still interesting to know what Stroustrup considers to be a method in C++.

    Method is an OO term and it denotes what an object can do, that is its behaviour. Because the ability to change an object's behaviour by the use of inheritance is an important OO feature, Stroustrup limits what should be called a method to functions exhibiting so called runtime polymorphism, namely virtual functions in C++.

    In Java on the other hand the term "function" simply isn't used. Every "function" is called a method regadless of properties or usage.
    Last edited by _uj; January 5th, 2009 at 02:56 AM.

  12. #12
    Join Date
    Mar 2007
    Posts
    155

    Re: What void foo() is really? - a Method? OR a Function?

    Thanks for all inputs !
    I have seen few C++ programmers call as a "Method". Also, they claim, they are really methods. But they couldn't give any convincing answer for why they call so.
    From the replies I can understand C++ standard tries to refer as "function". I don't know what factor separates a method and a function.

  13. #13
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by thomus07 View Post
    I don't know what factor separates a method and a function.
    I've tried to explain that. Method is an OO term. A method is a function that's related to an object's behaviour.

    Java is considered so OO that every function is called a method (by definition, function isn't used at all).

    C doesn't have any OO so no function should be called a method.

    In C++, all functions defined in a class (in principle the part of C++ that isn't C) could be called methods (this would then be equivalent to what's considered a method in Java). Stroustrup has a stricter definition. He thinks only functions which are virtual should be called methods.
    Last edited by _uj; January 5th, 2009 at 03:14 AM.

  14. #14
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by _uj
    Well, I don't think C++ actually defines the term "method". But it's still interesting to know what Stroustrup considers to be a method in C++.
    Yes, Plasmator already pointed out that the C++ standard does not use nor define the term "method". On the other hand, there are many C++ terms that are not defined or even mentioned in the C++ standard, so I think that it is fair to consider Stroustrup's definition as authoritative concerning C++.

    Quote Originally Posted by _uj
    Method is an OO term.
    If we look at it from an object oriented perspective rather than a language specific perspective, then I would argue that in any program in which OOP is used, there are methods, even if the program's programming language does not have native support for OOP, and "method" is not in that language's terminology.

    Quote Originally Posted by _uj
    In C++, all functions defined in a class (in principle the part of C++ that isn't C) could be called methods (this would then be equivalent to what's considered a method in Java).
    In other words, we could call member functions methods. However, that does not really answer thomus07's question: "what factor separates a method and a function"?

    Besides syntax, the difference between a member function and a non-member function is that the member function can access the object's (or class') internals. If that is used as the criterion, then what about friend functions?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  15. #15
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by laserlight View Post
    However, that does not really answer thomus07's question: "what factor separates a method and a function"?
    The decisive factor is how the function is used. If it defines object behaviour it's a method (according to OO terminology).

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured