下列程序运行结果是 。 class test{ long x; static int num; public: test (long m=0) {x=m;} test operator++(); test operator++(int); void Show() { cout<<"the num is:> <<",x="<> < <endl; } }; test test::operator++() { ++x; num is: the answer"> 参考答案: <span style="color:rgb(255, 0, 0)">The num is: 1,x=1 The num is: 2,x=3 The num is: 3,x=3 The num is: 3,x=1</span>
2、下列程序运行结果是 。 #include <iostream.h> class A { long x; public: A(long m) {x=m;} void Show() { cout<<"count="<> <<",x="<> < <endl; } a& operator++(); operator++(int); static int count; }; a::operator++() { ++x; ,x="<<x<<endl; A temp(*this); x++; return temp; } int A::count=1; void main() { A a(1); a.operator++(1); a.operator++(); a.Show(); }<br/><p class=" count="<<count++<<" answer"> 参考答案: <span style="color:rgb(255, 0, 0)">count=1,x=1 count=2,x=3 count=3,x=3</span>
3、下列程序运行结果是 。 class sample{ int x , y ; public : sample( ) { x=y=0 ; } sample( int i , int j) {x=i ; y=j ; } void copy( sample &obj) { *this=obj ; } sample operator--( ) { x-- ; y-- ; return *this; } void print( ){ cout << x << " " << y<< " " ; } } ; void main( ) { sample c1(1 , 2) , c2 ; --c1; c1.print( ) ; c2.copy(c1) ; --c2; c2.print( ) ; }