Thread: non-member function list

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    40

    non-member function list

    (C++ specific)
    Is a non-member function like I see sometimes listed in with a class reference list, any different that any function that comes into your project in (with) any needed include file for whatever reason(s) ?

    I mean other than relevance to the class which is why I'm guessing it's listed with the class as a non-member function.

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I'm having some trouble visualizing what you mean. Would you mind posting relevant source code?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by R_W_B
    Is a non-member function like I see sometimes listed in with a class reference list, any different that any function that comes into your project in (with) any needed include file for whatever reason(s) ?
    A "class reference list" is just documentation. It could be incomplete, out of sync with the actual code, etc.

    Basically, a non-member function could form part of a class' (extended) interface. It may be in the same namespace as the class, and may be declared in the same header. Whatever the case, you should include the appropriate header.
    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

  4. #4
    Registered User
    Join Date
    May 2016
    Posts
    40
    Quote Originally Posted by MutantJohn View Post
    I'm having some trouble visualizing what you mean. Would you mind posting relevant source code?
    Quote Originally Posted by laserlight View Post
    A "class reference list" is just documentation. It could be incomplete, out of sync with the actual code, etc.

    Basically, a non-member function could form part of a class' (extended) interface. It may be in the same namespace as the class, and may be declared in the same header. Whatever the case, you should include the appropriate header.
    Thanks that make it a bit clearer.

    This is the only quick reference I found that's like some of what I've seen. These are non-member function overloads.
    vector - C++ Reference
    (scroll to bottom).

  5. #5
    Guest
    Guest
    Yes, things like comparative operators such as in your example are nearly always implemented as non-member functions. And to answer your original question: not it's not any different – it's a "free floating" function that happens to come with that class' header. The function might be declared a friend of the class though.

    Btw, I do recommend cppreference as your go-to site when looking up standard library classes. cplusplus.com appears a lot more accessible, no question, but it's riddled with misleading examples and the occasional mistake. If you can look past the overwhelming amount of information, the former will serve you much better!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-03-2011, 01:14 PM
  2. Passing member variable as default arg to member function
    By Memloop in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2009, 06:49 PM
  3. Replies: 3
    Last Post: 07-23-2006, 01:09 PM
  4. Function Pointers to a Member, from a Member
    By littleweseth in forum C++ Programming
    Replies: 4
    Last Post: 11-01-2003, 02:12 AM
  5. private data member with public set member function
    By Mario in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2002, 10:53 AM

Tags for this Thread