オブジェクトを簡単にcoutで表示(挿入子<<の再定義・オーバーロード)

#include <iostream>
#include <sstream>
using namespace std;

class Base{
private:
	static int counter;
	int no;
public:
	Base(){
		no=counter;
		counter++;
	}
	int getNo() const{return no;}
	string to_string() const;
};

//オブジェクトの情報を文字列に変換
string Base::to_string() const{
	ostringstream s;
	s << "I am Sito No." << getNo();
	return s.str();
}

//挿入子の定義(Baseクラス)
ostream& operator<<(ostream& s, const Base& x){
	return s << x.to_string();
}

int Base::counter=0;//使徒は0号機から
const int SITO_MAX=10;//使徒の数

void main(){
	Base sito[SITO_MAX];
	for(int i=0;i<SITO_MAX;i++){
		cout << sito[i] << endl;//オブジェクトをcoutするだけで情報表示可能!
	}
	getch();//一時停止
}