前篇文章确实在使用new placement的时候,在某些情况下有问题.
class t : public b{public: t(int i, int k) { } 【程序编程相关:高质量c++/c程序设计指南摘要(二)(】
class b{public: b() { printf("b:b()\n"); }}; 【推荐阅读:Blog是什么?】
t( int i) { new (this) t(i, 10); //错误二 }}; 【扩展信息:什么是句柄?(转载)】
void set(int i) { this->~t(); new (this) t(i); //错误一 }
错误一在前篇文章的回复中已经说明了.
至于错误二,我个人认为只有在有继承关系的时候才存在问题.
例如 t a(10),结果调用基类b的构造函数两次,显然有问题.如果t没有父类呢?