Ant*_*ron 19 c++ undefined-behavior
#include <cstdio>
class A
{
public:
A(int){puts("3");};
int foo(){puts("4");return 10;}
};
int main()
{
A a(a.foo());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出4和3.
它在调用构造函数之前调用成员函数.标准是否定义了行为?
T.C*_*.C. 31
§12.7[class.cdtor]/p1:
对于具有非平凡构造函数的对象,在构造函数开始执行之前引用对象的任何非静态成员或基类会导致未定义的行为.
允许符合标准的编译器发出吹掉你腿的代码.
归档时间: |
|
查看次数: |
1154 次 |
最近记录: |