好久没写c++了,最近发现连构造函数的基本知识都忘记了。
还好查到了很多优秀的文章,彻底搞明白了
简短来说,构造函数中一般直接调用其它构造函数是没有用的,要用placement new 才行,具体看下面的参考链接
自己写的一个例子:
#include <iostream>
using namespace std;
class A
{
private:
int m;
public:
A()
{
new(this)A(2);
}
A(int i):m(i)
{}
void show()
{
cout<<m<<endl;
}
};
int main()
{
A a;
a.show();
return 0;
}
参考链接:
http://blog.youkuaiyun.com/race604/article/details/6921678
http://www.cnblogs.com/chio/archive/2007/10/20/931043.html
http://blog.youkuaiyun.com/zhangxinrun/article/details/5940019
http://www.cnblogs.com/the-tops/p/5587507.html