Dear brothers,
Hope you all are well :)
I just wonder how should we call the above void foo() correctly -Code:void foo() {}
Method? or Function?
Printable View
Dear brothers,
Hope you all are well :)
I just wonder how should we call the above void foo() correctly -Code:void foo() {}
Method? or 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
Functions which belong to class objects may be called methods. Non-class functions are not.
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.
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".
As Philip Nicoletti pointed out, Stroustrup's definition of method in C++ is virtual member function. That Wikipedia article is more general in nature.
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.
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.
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.
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
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 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"?Quote:
Originally Posted by _uj
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?