# What is the difference between the header file of the include class and the class name written directly?

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.