#include <iostream>
using namespace std;
namespace AAA
{
class Point
{
friend ostream& operator<<(ostream& os, const Point& aaa)
{
return os;
}
};
}
void main()
{
AAA::Point p;
// AAA::operator<<(cout, p);
// error : cout.operator<<( AAA::Point), 처리하자!!
cout << p; // 인자기반탐색이가지는장점.!!
}
// cout, endl 의원리
#include <stdio.h>
class ostream
{
public:
ostream& operator<<(char* s)
{
printf(s);
return *this;
}
ostream& operator<<( ostream&(*f)(ostream&))
{
return f(*this);
}
};
ostream cout;
///-----------------------------------------------------
ostream& endl(ostream& os)
{
os << "\n";
return os;
}
ostream& two_endl(ostream& os) // ostream에확장가능하다!!!!
{
os << "\n\n";
return os;
}
void main()
{
cout << "hello"; // cout.operator<<("hello")
cout << two_endl;
cout << endl; // cout.operator<<(함수포인터)
cout << "hello"; // cout.operator<<("hello")
endl( cout );
}