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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:13+00:00 2026-06-15T16:38:13+00:00

OK, this is stumping me. Relative C++ noob, but long experience with C# and

  • 0

OK, this is stumping me. Relative C++ noob, but long experience with C# and other languages.

Here’s a relatively simple distillation of the problem files:

/* GameObject.h */
#pragma once
#include <vector>
class GameObject {
    public:
    std::vector<Component *> *Components;
    GameObject();
    ~GameObject();
};


/* GameObject.cpp */
#include "GameObject.h"
#include "Component.h"
GameObject::GameObject() {
}

GameObject::~GameObject() {
}


/* Component.h */
#pragma once
class Component {
    public:
    GameObject *Owner;
    Component();
    ~Component();
};


/* Component.cpp */
#include "GameObject.h"
#include "Component.h"
Component::Component() {
}
Component::~Component() {
}

This generates 21 totally irrelevant errors in Visual C++ 2012, I guess stemming from the fact that it couldn’t compile Component:

C2065: 'Component' : undeclared identifier  gameobject.h    10
C2059: syntax error : '>'   gameobject.h    10
C2143: syntax error : missing ';' before '}'    gameobject.h    14
C2143: syntax error : missing ';' before '{'    component.h 3
C2143: syntax error : missing ';' before '}'    component.h 11
C2143: syntax error : missing ';' before '{'    gameobject.cpp  8
C2143: syntax error : missing ';' before '}'    gameobject.cpp  9
C2143: syntax error : missing ';' before '{'    gameobject.cpp  13
C2143: syntax error : missing ';' before '}'    gameobject.cpp  14
C2143: syntax error : missing ';' before '}'    gameobject.cpp  16
C1004: unexpected end-of-file found gameobject.cpp  16
C2065: 'Component' : undeclared identifier  gameobject.h    10
C2059: syntax error : '>'   gameobject.h    10
C2143: syntax error : missing ';' before '}'    gameobject.h    14
C2143: syntax error : missing ';' before '{'    component.h 3
C2143: syntax error : missing ';' before '}'    component.h 11
C2653: 'Component' : is not a class or namespace name   component.cpp   8
C2143: syntax error : missing ';' before '{'    component.cpp   8
C2143: syntax error : missing ';' before '}'    component.cpp   9
C2653: 'Component' : is not a class or namespace name   component.cpp   13
C1903: unable to recover from previous error(s); stopping compilation   component.cpp   13

Any ideas? It makes sense in the design for Component to have a pointer to GameObject, and GameObject to have a vector of pointers to Components, so I’m not about to rearchitect to avoid that. I’m guessing I’m just doing something wrong with the header files.

Thanks in advance for any ideas, this one’s driving me crazy.

  • 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-15T16:38:14+00:00Added an answer on June 15, 2026 at 4:38 pm

    All you need to fix this is to add forward declarations – Component before GameObject definition and vice versa

    class GameObject;
    class Component {
    ...
    

    and

    class Component;
    class GameObject{
    ...
    

    Technically you just need the 2nd one because of the way you order your .h files. But it is better you add both.

    The reason for this is because if we think of your .h as independant C++ files, by the time we(the compiler) come across the definition of the vector of Component pointers (why is this a pointer to a vector??), we still have no idea what Component is. It could be a class, a function, a typo, anything. This is why you need a forward declaration to let the compiler know to assume it is a class.

    This would work only in the case of pointers/references to other classes. If it were a vector of Component objects, you would have had no choice but to include the header before the definition.

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

Sidebar

Related Questions

This may be pretty simple but it's stumping me. I'm trying to return a
I'm sure this has got a simple answer, but it's stumping me :( I'm
This one has been stumping me for a while. But I'm no expert. This
this may seem like a stupid question, but it is stumping me nontheless. I'm
This is really stumping me today. I'm sure its not that hard, but I
Here's an odd problem that's been stumping me for a bit. The program is
I'm quite new to using PHP but this has been stumping me for a
I'm a weak perl user (and manipulator of arrays), and this problem is stumping
I feel like this should be easy, but it seems to be stumping me.
I know a lot about C# but this one is stumping me and Google

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.