Which is correct?

This is a discussion on Which is correct? within the C++ Programming forums, part of the General Programming Boards category; In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious....

  1. #1
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    Which is correct?

    In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious.
    -- Will you show me how to c++?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by mramazing View Post
    In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious.
    The former is most commonly used, but whichever...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    Thank you!
    -- Will you show me how to c++?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    Quote Originally Posted by mramazing
    In C++ are member functions supposed to be called 'member functions' or 'class methods'?
    You can use the term method to refer to a virtual member function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    "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;
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    Quote Originally Posted by dwks
    "method" is a generic object-oriented term, and "member function" is a distinctly C++ term, but they mean the same thing in this context.
    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
    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).
    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 Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Quote Originally Posted by laserlight View Post
    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.
    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.

    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.
    True -- I was trying to avoid circular definitions here and so presented an example instead.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,313
    Quote Originally Posted by mramazing View Post
    In C++ are member functions supposed to be called 'member functions' or 'class methods'? Just curious.
    "To-may-to, To-mah-to"
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i solved this recursion, is it correct?
    By jackhasf in forum C Programming
    Replies: 7
    Last Post: 12-21-2009, 04:49 AM
  2. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 03:50 PM
  3. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  4. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 01:03 PM
  5. Check if input password is correct
    By kagemand in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2001, 08:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21