Compilation error: the header file is included, but the prompt class is not declared (the header file contains each other)

Source: Internet
Author: User

Environment:

Ubuntu 11.10g ++

Error:

Compile a header fileCode(A. H contains B. H, B. H contains a. h)

However, an error occurs during compilation. The prompt is: Class B is not declared in the. h file; Class A is not declared in the B. H file.

Error analysis:

# Include <> has been used in the header file to introduce the header file of the other party.

At the beginning, I thought there was a name error and I was checking it.

If no input error is found, encoding is required.

I have encountered similar problems when the header files contain each other before, but it takes too long to forget...

Solution:

Declare Class B in A. H file

Add the following statement before defining Class:

Class B;

Similarly, the same operation is performed in B. H.

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.