要在头文件中 #include 基类的头文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cloud323/article/details/82106797

一,要在头文件中#include基类的头文件

如果不在头文件#include基类的头文件,编译时会出错,提示基类是未定义的,例如:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

//头文件中没有#include基类的头文件
//#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

编译时出错:

e:\qtworkspace\test\mainwindow.h(11) : error C2504: “QMainWindow”: 未定义基类e:\qtworkspace\test\mainwindow.h:11: error: C2504: “QMainWindow”: 未定义基类

MainWindow 类继承于QMainWindow,如果不包含QMainWindow的头文件,就不知道QMainWindow类中声明了哪些方法。

猜你喜欢

转载自blog.csdn.net/cloud323/article/details/82106797