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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:35:03+00:00 2026-06-16T11:35:03+00:00

Possible Duplicate: C++ Undeclared Identifier (but it is declared?) Im getting the error sprite.h(20):

  • 0

Possible Duplicate:
C++ Undeclared Identifier (but it is declared?)

Im getting the error sprite.h(20): error C2065: 'Component' : undeclared identifier when I try to compile (I got a couple other files as well). Below is the sprite.h file. I cant for the life of me figure out what is causing this problem.

#ifndef SPRITE_H
#define SPRITE_H

#include "Image.h"
#include "Rectangle.h"
#include <string>
#include <SDL.h>
#include <vector>
#include "Component.h"

namespace GE2D {

    class Sprite {
    public:
        Sprite();
        Sprite(Image *i);
        Sprite(Image *i, int x, int y);
        Sprite(char *file, bool transparentBg, int x, int y, int w, int h);
        virtual ~Sprite();
        virtual void tick(SDL_Surface *screen, std::vector<Sprite*>* sprites, std::vector<Component*>* components);
        virtual void handleEvent(SDL_Event eve);
        virtual void draw(SDL_Surface *screen);
        void setPosition(int x, int y);
        const Rectangle& getRect() const;
        const Image& getImage() const;
        const Sprite& operator=(const Sprite& other);
        Sprite(const Sprite& other);
    protected:

    private:
        Image image;
        Rectangle rect;
    };

}
#endif

In the .cpp file tick() is defined like this:

void Sprite::tick(SDL_Surface *screen, std::vector<Sprite*>* sprites, std::vector<Component*>* components) {}

tick() is supposed to take two vectors like they do now, but maybe there’s a better way to do that which might solve this problem?

EDIT
As requested, here is Component.h as well:

#ifndef COMPONENT_H
#define COMPONENT_H

#include "Rectangle.h"
#include "Component.h"
#include "Sprite.h"
#include <vector>
#include <SDL.h>

namespace GE2D {

    class Component {
    public:
        Component();
        virtual ~Component();
        virtual void draw(SDL_Surface *screen) = 0;
        virtual void tick(SDL_Surface *screen, std::vector<Sprite*>* sprites, std::vector<Component*>* components) = 0;
        virtual void handleEvent(SDL_Event eve) = 0;
        const Rectangle& getRect() const;

    protected:
        Component(int x, int y, int w, int h);
    private:
        Rectangle rect;
    };

}
#endif
  • 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-16T11:35:05+00:00Added an answer on June 16, 2026 at 11:35 am

    Sprite.h includes Component.h which includes Sprite.h, giving a circular dependency which can’t be resolved.

    Luckily, you don’t need to include the headers at all. Each class only refers to a pointer to the other class, and for that a simple declaration is enough:

    class Component;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: g++ “is not a type” error The following does not compile: 1
Possible Duplicate: Building android source code I am getting the following error while building
Possible Duplicate: C++ template, linking error I am attempting to implement a selection sort,
Possible Duplicate: Why does gcc have “â” in all its error messages? New to
Possible Duplicate: What is 0x10 in decimal? I notice that Console.WriteLine(18); writes 18, but
Possible Duplicate: Model.find(1) gives ActiveRecord error when id 1 does not exist If there
Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: ios::nocreate error while compiling a C++ code i have been working on
Possible Duplicate: Subtract days from a date in javascript I have got a JavaScript
Possible Duplicate: What is a stack overflow error? It just happens when I declare

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.