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

This is a discussion on Is there a way to call an operator function from another member function? within the C++ Programming forums, part of the General Programming Boards category; Code: I have class C{ ... C& operator<<(C& os, const char* str) { ... } void display() { Is there ...

  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
    22,271
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 02:02 PM
  2. Error: cannot call member function without object
    By TIMBERings in forum C++ Programming
    Replies: 7
    Last Post: 04-15-2010, 05: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, 12:01 PM
  5. Replies: 6
    Last Post: 11-08-2005, 03:05 PM

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