关于运算符优先级问题
blldw 2008-09-24 12:15:27 #include <iostream>
class Integer {
public:
Integer(int i = 0) : _i(i) {}
Integer& operator++() {
std::cout << "++res is called" << std::endl;
++_i;
return (*this);
}
operator int() {
return _i;
}
private:
int _i;
};
class A {
public:
bool operator*() {
std::cout << "*A is called" << std::endl;
return true;
}
A& operator++(int) {
std::cout << "A++ is called" << std::endl;
return (*this);
}
};
int main()
{
A a;
Integer i;
if (*a++) ++i;
return 0;
}
执行结果为什么是
A++ is called
*A is called
++res is called
而非
*A is called
A++ is called
++res is called
?