View Poll Results: How do you call void foo()
- Voters
- 9. You may not vote on this poll
-
January 4th, 2009, 10:12 PM
#1
What void foo() is really? - a Method? OR a Function?
Dear brothers,
Hope you all are well
I just wonder how should we call the above void foo() correctly -
Method? or Function?
-
January 4th, 2009, 10:17 PM
#2
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by thomus07
Method? or Function?
This shouldn't be a poll. It's "function".
-
January 4th, 2009, 10:27 PM
#3
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
-
January 4th, 2009, 10:35 PM
#4
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by Thu
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.
-
January 4th, 2009, 11:00 PM
#5
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.
-
January 4th, 2009, 11:05 PM
#6
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by lindley
functions which belong to class objects may be called methods. Non-class functions are not.
+1
-
January 4th, 2009, 11:18 PM
#7
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by Arjay
+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
-
January 4th, 2009, 11:52 PM
#8
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".
-
January 5th, 2009, 12:48 AM
#9
Re: What void foo() is really? - a Method? OR a Function?
Last edited by _uj; January 5th, 2009 at 12:51 AM.
-
January 5th, 2009, 01:14 AM
#10
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.
-
January 5th, 2009, 02:37 AM
#11
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by laserlight
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.
-
January 5th, 2009, 02:51 AM
#12
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.
-
January 5th, 2009, 03:06 AM
#13
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by thomus07
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.
-
January 5th, 2009, 03:46 AM
#14
Re: What void foo() is really? - a Method? OR a Function?
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++.
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.
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?
-
January 5th, 2009, 04:03 AM
#15
Re: What void foo() is really? - a Method? OR a Function?
Originally Posted by laserlight
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).
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|