地沟油问题跟三氯氰胺的奶粉是一回事,监管环节有漏洞
分类: C/C++
2010-08-19 16:43:32
ISO C++ Standard 2003给出的描述是:“In certain cases, an implementation is permitted to eliminate the copying inherent in this direct-initialization by constructing the intermediate result directly into the object being initialized。”
因为T x = a相当于T x(T(a)),上段C++标准大意是允许编译器直接将中间结果T(a)构造在x的地址空间,这样就无需再将T(a)拷贝到x了。注意C++标准用的“允许”而不是“强制”。换句话说,编译器可据自己心情选择优化与否,甚至可选择时优时不优。幸运的是,大多数现代编译器都会很敬业地选择优化,如VC9,GCC等。
其它解释