Why does Qt contain empty class definitions of existing classes in header files?

I read the examples on the Qt page and wonder why they add references to existing classes in their example code :

#ifndef HTTPWINDOW_H
#define HTTPWINDOW_H

#include <QDialog>

class QFile;
class QHttp;
class QHttpResponseHeader;
class QLabel;
class QLineEdit;
class QProgressDialog;
class QPushButton;

class HttpWindow : public QDialog
{
...
+3
source share
3 answers

These are advanced declarations. Using them can (in some cases) eliminate the need to # include appropriate header files, thereby speeding up compilation. The C ++ standard library does something similar with a header <iosfwd>.

+10
source

This is called Forward Declaration.

, ,

+9

As mentioned above, this is just a forward declaration. And in the header file, these classes will usually be used through pointers, so a full class declaration is not required before .cpp. So, for example, your title may continue ...

class HttpWindow : public QDialog
{

QFile *m_pFile;
QHttp *m_pHttp;
...
}
+1
source

Source: https://habr.com/ru/post/1713051/


All Articles