当前位置: 首页 > 工具软件 > jquery widget > 使用案例 >

Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::Widget)

劳仲渊
2023-12-01
#include <QCoreApplication>
#include <iostream>
using namespace std;
class Base
{
public:
    Base() :m_num(0){
        cout << "this is Base()" << endl;
        cout<<m_num<<endl;
    }
    Base(int val):m_num(val){
        cout << "this is Base(int val)" << endl;
    }
    void fun(int a);
private:
    int m_num;
};

void Base::fun(int a)
{
   m_num=a;
}

class BaseChild: public Base
{
public:
    BaseChild(){
        cout << "this is BaseChild()" << endl;
    }
    BaseChild(int val);
    void fun(int a,int b);
    /*BaseChild(int val): Base(val){
        cout << "this is BaseChild(val)" << endl;
    }*/
private:
    int n_num;
};
BaseChild::BaseChild(int val) : Base(val),n_num(val)
{
cout<<"sdfas"<<endl;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    BaseChild child1(5);
      //  BaseChild child2(5);

        return 0;


    return a.exec();
}

http://www.cnblogs.com/findumars/p/9231742.html

https://blog.csdn.net/weibo1230123/article/details/75348785

https://blog.csdn.net/Pg_dog/article/details/70224675

BaseChild是类, ::是作用域,::后面的BaseChild(int val)是构造函数,:后面的Base(val)是指定基类的构造函数,不明确指定的话是默认构造函数,n_num(val) 是对BaseChild类里面的成员变量做初始化。

将上面这句话和Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::Widget)作比较,便可以理解。

 类似资料: