这里补充QT的实例:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) //
, ui(new Ui::MainWindow) //这里就是使用了初始化列表的方式初始化属性;
{
ui->setupUi(this);
}
先构造成员再构造对象,析构反之(穿脱原则);
#include<iostream>
#include<string>
using namespace std;
class a
{
public:
a() {
cout<< "this is a 构造调用" << endl;
}
~a()
{
cout << "this is a 析构调用" << endl;
}
};
class c
{
public:
a A;
c()
{
cout << "this is c 构造函数" << endl;
}
~c()
{
cout << "this is c 析构函数" << endl;
}
};
int main()
{
c C;
system("pause");
return 0;
}