#include <iostream>
using namespace std;
class Obj
{
public:
void operator << (int s)
{
cout <<"int: " << s << flush <<'\n';
}
void operator << (double s)
{
cout <<"double: " << s << flush <<'\n';
}
void operator << (string s)
{
cout <<"string: " << s << flush <<'\n';
}
void A(int s)
{
operator << (s);
}
void A(double s)
{
operator << (s);
}
void A(string s)
{
operator << (s);
}
};
int main(void)
{
Obj K;
Obj *P = new (Obj);
int x=12345;
K << x;
K << x*0.01;
K << "115 = 114+1";
K.A(556);
K.A(556.01);
K.A("I am a doctor.");
P->A("GameOver");
*P << "GameOver2";
return 0;
}
输出结果:
int: 12345
double: 123.45
string: 115 = 114+1
int: 556
double: 556.01
string: I am a doctor.
string: GameOver
string: GameOver2
Process exited with return value 0
Press any key to continue …