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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:36:37+00:00 2026-05-28T13:36:37+00:00

I am throwing myself in the cold blizzard of learning C++. I already know

  • 0

I am throwing myself in the cold blizzard of learning C++. I already know Java but C++ seems odd on certain thing.

Here is the thing : I have a class A and a class B. Class A have an instance of class B inside of itself. Class B needs to be able to call some class A methods so, I put a pointer to class A inside class B’s constructor, and store it inside a variable so I can retrieve these methods with this variable.

Here is my code (simplified) :

ClassA.h

#ifndef CLASSA
#define CLASSA

#include "ParentClass.h"
#include "ClassB.h"

class ClassA : public ParentClass {

private:
ClassB *classB;

public:
ClassA(void);
virtual ~ClassA(void);

};
#endif

ClassA.cpp

   #include "ClassA.h"

   //-----------------------------------------------------
   ClassA::ClassA(void){
    classB= new ClassB(this);
   }
   //-----------------------------------------------------
   ClassA::~ClassA(void)
   {
   }
   //-----------------------------------------------------

ClassB.h

#ifndef CLASSB
#define CLASSB

#include "ClassA.h"

class ClassB{

public:
ClassB(ClassA &pClassA){ classA = pClassA; };
ClassA *getClassAInstance(){ return classA; };

private:
ClassA *classA;
};
#endif

ClassB.cpp

#include "ClassA.h"

/*ClassB::ClassB(void){
classA= pClassA;
}*/

Visual Express doesn’t give errors but when I compile, it says that class B doesn’t recognize what is a class A. What the hell ?

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2061: syntax
error : identifier ‘ClassA’

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C2143: syntax
error : missing ‘;’ before ‘*’

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C4430:
missing type specifier – int assumed. Note: C++ does not support
default-int

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C4430:
missing type specifier – int assumed. Note: C++ does not support
default-int

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): warning C4183:
‘getClassAInstance’: missing return type; assumed to be a member
function returning ‘int’

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C2143: syntax
error : missing ‘;’ before ‘*’

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C4430:
missing type specifier – int assumed. Note: C++ does not support
default-int

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C4430:
missing type specifier – int assumed. Note: C++ does not support
default-int

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2065:
‘classA’ : undeclared identifier

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2065:
‘pClassA’ : undeclared identifier

1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C2065:
‘classA’ : undeclared identifier

Undeclared what ? Returning int ?

undeclared identifier

Why? I included everything, right ? Any ideas what is wrong, guys ?

  • 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-28T13:36:37+00:00Added an answer on May 28, 2026 at 1:36 pm

    This is because of a circular reference between your header files. You can break it by forward-declaring one of the classes inside the header of the other, like this:

    #ifndef CLASSA
    #define CLASSA
    
    #include "ParentClass.h"
    //#include "ClassB.h" <<<<< Circular reference is now broken
    
    class ClassB; // Added a forward declaration for use below.
    
    class ClassA : public ParentClass {
    
    private:
    ClassB *classB;
    
    public:
    ClassA(void);
    virtual ~ClassA(void);
    
    };
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completey new to C# and I've already given myself a headache. I know
Ok, so I have gotten myself completely confused here. I am not sure why
There is a minor annoyance I find myself with a lot - I have
I've been throwing myself at Facebook dev for a couple of weeks now and
I frequently find myself having to do an extra nil check (to avoid throwing
update I solved this problem by myself. I put it here for further reference.
I have a test project I'm using to familiarise myself with VB6. Just a
I'm currently learning ANTLR for myself. First of I decided to write the simplest
I'd love to hear what advice the Clojure gurus here have about managing state
I have this line in one of my scripts and its throwing a deprecated

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.