In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious.
Printable View
In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious.
Thank you!
You can use the term method to refer to a virtual member function.Quote:
Originally Posted by mramazing
"method" is a generic object-oriented term, and "member function" is a distinctly C++ term, but they mean the same thing in this context. However, the term "class method" sounds, at least from a Java perspective, like it refers to static functions (i.e. functions that can be called without this pointer, without an object to operate on).
Code:class Something {
public:
static void staticFunc() {}
};
int main() {
// called without an object of type Something to operate on
Something::staticFunc();
return 0;
}
Somewhat: as I mentioned, method can be used as a C++ term to refer specifically to a virtual member function, which is really more akin to a method in a general OOP sense since you cannot override a non-virtual member function.Quote:
Originally Posted by dwks
Agreed, though I note that "static functions" could refer to free functions that are declared static, but here the use is to refer to static member functions.Quote:
Originally Posted by dwks
I haven't really seen that distinction made before, but it makes sense. So I guess you could define a "member function" as a function which resides inside a class, whether virtual or non-virtual or static.
True -- I was trying to avoid circular definitions here and so presented an example instead. ;)Quote:
Agreed, though I note that "static functions" could refer to free functions that are declared static, but here the use is to refer to static member functions.