Saturday, August 18, 2012

Object constructed by the << operator





#include <iostream>

struct Void{
  Void(...){}
};

std::ostream& operator<<(std::ostream&  o,const Void& v){
    return o<<"stolen by void!";

}


struct CannotPrint{
};



int main(){
  CannotPrint cp;
  std::cout<<cp<<std::endl;
}

in this case, a Void object is constructed and printed
the same for the constructor

 template<typename T> Void(const T&){}


No comments:

Post a Comment