#include <iostream>
#include <stdio.h>
using namespace std;
class MyCin
{
bool bStop;
public:
MyCin():bStop(false) { }
operator bool( ) { //重载类型强制转换运算符 bool
return !bStop;
}
MyCin& operator =(MyCin& b){
return b;
}
MyCin & operator >> (int& n)
{
cin >> n;
if( n == 100)
bStop = true;
return * this;
}
};
int main()
{
MyCin m;
int n;
while( m >> n) //调用强制类型转换运算符
cout << "number:" << n << endl;
MyCin x;
x = m;
while( x >> n) //调用强制类型转换运算符
cout << "number:" << n << endl;
return 0;
}
【C++】强制类型转换运算符的重载
最新推荐文章于 2023-10-27 19:02:29 发布