重载逗号操作符
#include <iostream>#include <string>using namespace std;class Comma{private: int mvalue;public: Test ( int i ){ this->mvalue = i; } int value ( void ){ return mvalue; }};Comma& operator , ( const Comma& a, const Comma& b ){ return const_cast<Comma&> (b);}void func ( Comma& i ){ cout << "func(): i = " << i.value() << endl;}int main ( int argc, char** argv ){ Comma t0(0); Comma t1(1); Comma tt = ( t0, t1 ); cout << tt.value() << endl; system ( "pause" ); return 0;}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。