第一次发现,求解释
#include "stdafx.h"#include <iostream>using namespace std;class M //C++11 delegating constructors{ int x, y; char *p;public: M() { M(10); }; M(int v) : x(v), y(0), p(new char [0]) { } //#1 target };int main(int argc, char* argv[]){ M m(); // M m printf("Hello World!\n"); return 0;}#include <iostream>#include <string>using namespace std;class M //C++11 delegating constructors{ int x, y; char *p;public: M() { printf("默认构造函数\n"); M(10);//还有这个地方原则上是不会有任何作用的 需要自定义=运算符然后赋值 }; M( const M &m ) { printf("拷贝构造函数\n"); x = m.x; y = m.y; p = new char[strlen(m.p)+1]; strcpy(p,m.p); } M(int v) : x(v), y(0), p(new char [1]) { printf("带参数构造函数\n"); } //#1 target int Getx()const { return x; } };int main(int argc, char* argv[]){ M m(); // M m printf("Hello World!\n"); M n; printf("%d\n",n.Getx()); return 0;}