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 6688229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:22:50+00:00 2026-05-26T05:22:50+00:00

I have a basic question that has bothered me for sometime. When using a

  • 0

I have a basic question that has bothered me for sometime.

When using a Class within a Class I can define the header of the Class I want to use in the header file. I have seen two ways of doing this and would like to know the difference between the two methods?

ex1

#include "ClassA.h"

class ClassB {

   public:
     ClassB();
     ~ClassB();
     ClassA* a;
};
#endif

ex2 Here is the other way of doing it. The ClassA Header would be defined in ClassB source file.

class ClassA;

class ClassB {

   public:
     ClassB();
     ~ClassB();
     ClassA* a;
};
#endif

What are the differences with these two methods?

  • 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-05-26T05:22:51+00:00Added an answer on May 26, 2026 at 5:22 am

    The comlpete layout of the classA is known to the compiler when you include the class definition.

    The second syntax is called Forward declaration and now classA is an Incomplete type for the compiler.

    For an Incomplete type,
    You can:

    • Declare a member to be a pointer or a reference to the incomplete type.
    • Declare functions or methods which accepts/return incomplete types.
    • Define functions or methods which accepts/return pointers/references to the incomplete type (but without using its members)

    But You cannot:

    • Use it as a base class.
    • Use it to declare a member.
    • Define functions or methods using this type.
    • Use its methods or fields, in fact trying to dereference a variable with incomplete type.

    So Forward Declaring the class might work faster, because the complier does not have to include the entire code in that header file but it restricts how you can use the type, since it becomes an Incomplete type.

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

Sidebar

Related Questions

I'm learning clojure and have a very basic question: given that clojure has type
Maybe a basic question but let us say I have a string that is
Another basic Rails question: I have a database table that needs to contain references
This is probably a basic html/css question... I have a simple one-button form that
I have a basic question, in the Django template language how can you tell
I have really basic question. How can I get form id by input element
I have another SQL/access 2007 question that seems really basic but I'm not sure
Very basic question: I am coding a web app that has a handful of
This has to be a common question that all programmers have from time to
Have a basic question on running PHP applications using Eclipse PHP on Ubuntu. I

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.