读书人

新手求解答~解决思路

发布时间: 2012-03-27 13:44:24 作者: rapoo

新手,求解答~~
#include <iostream>
using namespace std;
class A
{
public:
A()
{
static int i=1;
//cout<<"construct "<<i<<endl;
printf("%d %d \n",i++,++i);
}
~A()
{
static int i=2;//////测试出来好像应该是作用域覆盖
//cout<<"destruct "<<i<<endl;
printf("%d %d\n",i++,++i);

}

};
int main()
{
A *pA=new A;
delete pA;

}

[解决办法]
What's the value of i++ + i++?
It's undefined. Basically, in C and C++, if you read a variable twice in an expression where you also write it, the result is undefined. Don't do that.

i see.
[解决办法]
去看这篇文章

http://blog.csdn.net/qqianqq/article/details/6733681

读书人网 >C++

热点推荐