Thread: operator overloading

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    1

    operator overloading

    Code:
    Logger& Logger::operator<<(Logger & (*m)(Logger &)){
      (*m)(*this);
      return *this;
    }
    
    Logger& Logger::operator<<(double lvalue){
           ...
      return *this;
    }
    
    ... (more overloaded << operators here)
    I'm wondering what (Logger & (*m)(Logger &)) means, and then what the body of the function does.
    Because right now, I don't understand how something like

    Code:
    int temp = 9;
    Logger log;
    log << "hi there" << temp << endl;
    works.

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    I'm wondering what (Logger & (*m)(Logger &)) means
    It means that operator<< takes a pointer to a function that takes a reference to a Logger as a parameter and returns a reference to a Logger. Put simply, it let's you create and use manipulators like the standard streams:
    Code:
    Logger& manip(Logger& log) {
      // Do something with log
    }
    
    log_stream << manip;
    Just because I don't care doesn't mean I don't understand.

Popular pages Recent additions subscribe to a feed