- 论坛徽章:
- 0
|
#include <iostream.h>
class integer{
int i;
public:
integer(int a=0):i(a){}
int value() const{
return i;
}
void set(int a){
i=a;
}
integer& operator++(){
i++;
cout<<"here"<<endl;
return *this;
}
integer operator++(int){
int oldi=i;
i++;
cout<<"here2"<<endl;
return integer(oldi);
}
};
void result(const integer& i,const char*op){
cout<<"operation:"<<op<<"result="<<i.value()<<endl;
}
void curValue(const integer& i){
cout<<"current value="<<i.value()<<endl;
}
void main(){
integer i(100);
curValue(i);
result(++i,"++i");//编译器怎么来决定调用那个函数?
curValue(i);
result(i++,"i++");
curValue(i);
}
3x |
|