operator overloading

This is a discussion on operator overloading within the C++ Programming forums, part of the General Programming Boards category; Code: Logger& Logger::operator<<(Logger & (*m)(Logger &)){ (*m)(*this); return *this; } Logger& Logger::operator<<(double lvalue){ ... return *this; } ... (more overloaded ...

  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

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