Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8495297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:32:06+00:00 2026-06-10T23:32:06+00:00

Why declare the class that you included as a header file? #include TreeCallObj.h #include

  • 0

Why declare the class that you included as a header file?

#include "TreeCallObj.h"
#include "TreeDevObj.h"
#include "TreeDevCallObj.h"

class TreeCallObj; //what is the purpose of this line ?
class TreeDevObj;  //what is the purpose of this line ?
class TreeDevCallObj;  //what is the purpose of this line ?


class Apple
{
public:
...
private:
...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:32:08+00:00Added an answer on June 10, 2026 at 11:32 pm

    Consider this:

    //a.h
    #ifndef A_H
    #define A_H
    
    #include "b.h"
    class A
    {
       B* b;
    };
    #endif
    
    //b.h
    #ifndef B_H
    #define B_H
    
    #include "a.h"
    class B
    {
       A* a;
    };
    #endif
    

    Now you try to include one of the files in a different one, say you #include "a.h".

    The compiler will parse it as:

    #ifndef A_H
    #define A_H
    

    fine – A_H isn’t defined

    #include "b.h"
    

    try to paste the contents:

    #ifndef B_H
    #define B_H
    

    ok, since B_H isn’t defined

    #include "a.h"
    

    this will not define A, because A_H is defined. So next, we have

    class B
    {
       A* a;
    };
    

    which will lead to an error, because A wasn’t defined or declared before the use.

    The forward declaration fixes this.

    Of course, the best solution to this is to not include at all (unless you absolutely have to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the header file testcode.h #ifndef TESTCODE_H #define TESTCODE_H class A { public:
How would I declare a class that has a method/message that takes a selector,
I am trying to forward declare a class that is derived from a template
I have a very basic data class that is subclassed from NSObject. I declare
I've noticed that a lot of Objective-C examples will forward declare classes with @class,
In my class I want to declare an event that other classes can subscribe
Is there a way to declare that the variable type of a generic class
When you declare a type parameter for the class, you can simply use that
I have the following header file: #ifndef CLASSES_H #define CLASSES_H class Mouse // Handles
I have a class called GameState in its own file and that class has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.