正确理解Qt中构造函数:Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::Widget)
#include <iostream>
using namespace std;
class Base
{
public:
Base():m_num(0){
cout << "this is Base()" << endl;
}
Base(int val):m_num(val + 1){
cout << "this is Base(int val) and m_num = " << m_num << endl;
}
private:
int m_num;
};
class BaseChild : public Base
{
public:
BaseChild(){
cout << "this is BaseChild()" << endl;
}
BaseChild(int val) : Base(val), m_num(val){
cout << "this is BaseChild(int val) and m_num = " << m_num << endl;
}
private:
int m_num;
};
int main(int argc, char *argv[])
{
BaseChild child1;
BaseChild child2(5);
return 0;
}
输出结果:
this is Ba