During header file writing
There are some class qfile and other things that seem to be declared... for example below
# Ifndef window_h
# Define window_h
Qt_begin_namespace
Class qtcpserver;
Class qtcpsocket;
Class qprogressbar;
Class qlabel;
Class qdialogbuttonbox;
Class qfile;
Qt_end_namespace
// Code end
Class qaction;
Class qcheckbox;
...
If no declaration is made, an error similar to the following will occur.
Iso c ++ forbids declaration of 'qfile' with no type
So what is this ????
This is because only the pointer declarations of these classes are in the header file and are not actually instantiated. In the CPP file corresponding to this header file
# Include <qdialogbuttonbox>
# Include <qfile>
...
These classes will be instantiated in the CPP file.
It is also possible to directly include # include <qdialogbuttonbox> # include <qfile> in the header file. It seems that it can reduce the relevance of each file during compilation, it will not trigger the re-Compilation of a large number of other files when changing the partial classification. There is no difference when doing small projects, but it will take several hours to compile a compilation, the advantage of doing so is apparent.
ClassThe class name only declares that such a class exists, but you cannot get any specific information about this class through this declaration. In this way, you can declare a pointer of this type elsewhere.
The include header file is associated with the entire header file.
Use classThe class name is generally used to remove compilation dependencies and reduce compilation consumption.
# Include "XX. H" directly expands the XX. h file during compilation, so all interfaces in it can be used to declare objects. But class xx; this method does not. You can only use its pointer or reference. You cannot create a declarative object.