Thread: Is there a way to call an operator function from another member function?

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    51

    Is there a way to call an operator function from another member function?

    Code:
    I have class C{
    ...
    
    C& operator<<(C& os, const char* str) {
    ...
    }
    
    void display() {
    Is there anyway I can call operator<< in here?
    
    }

  2. #2
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    *this

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you don't actually need to directly access any private member variables, then make that member function into a non-member non-friend 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

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    51
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. illegal call of non-static member function
    By mark103 in forum Tech Board
    Replies: 8
    Last Post: 04-17-2011, 01:02 PM
  2. Error: cannot call member function without object
    By TIMBERings in forum C++ Programming
    Replies: 7
    Last Post: 04-15-2010, 04:21 AM
  3. Why can = operator not be overloaded with member function?
    By chottachatri in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2008, 04:30 PM
  4. illegal call of non-static member function
    By JackR in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2007, 11:01 AM
  5. Replies: 6
    Last Post: 11-08-2005, 03:05 PM