Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Circular inclusion problem

$
0
0
I think I am having the problem mentioned in the title, but I can't be sure of it as well... Got 3 classes, GameMode, Entity, Paddle. Paddle Inherit from Entity, and both Paddle and Entity need to #include "GameMode.h" in order to pass down the constructor a GameMode* and store it inside of every Entity. I pretty much forward declared everything inside everything else but stuff just won't compile, the error I am getting is C2504 "Entity: base class undefined" . I'll paste below the .h and .cpp for the Entity class, and only .h for the other two. Can someone tell me what am I doing wrong? Entity.h #pragma once #include "SDL2\SDL.h" #include "GameMode.h" #include "Utility.h" using namespace util; class GameMode; enum class PivotMode: Uint8 {CENTER,TOP_LEFT}; class Entity { protected://variables float XCenter; float YCenter; SDL_Rect CollisionBox; SDL_Texture* Sprite; GameMode* Game; SDL_Renderer* Renderer; public://constructors Entity(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path); virtual ~Entity(); Entity(const Entity&) = delete; Entity& operator=(const Entity&) = delete; Entity(Entity&&) = delete; Entity& operator=(Entity&&) = delete; public://methods virtual void Update(float deltaTime) = 0; virtual void Draw(float interpolation) = 0; private://methods SDL_Texture* RequestTexture(std::string path)const; void SetCollisionBox(int x, int y, PivotMode InputMode); }; Entity.cpp #include "Entity.h" Entity::Entity(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path) :Game{ gameRef }, XCenter{ static_cast<float>(x) }, YCenter{ static_cast<float>(y) } { if (Game) { Renderer = Game->GetRenderer(); } Sprite = RequestTexture(path); if (Sprite) { SetCollisionBox(x, y, inputMode); } } Entity::~Entity() { } SDL_Texture* Entity::RequestTexture(std::string path)const { if (Game->IsRunning()) { return Game->RequestTexture(path); } return nullptr; } void Entity::SetCollisionBox(int x, int y, PivotMode InputMode) { SDL_QueryTexture(Sprite, nullptr, nullptr, &CollisionBox.w, &CollisionBox.h); switch (InputMode) { case PivotMode::CENTER: { CollisionBox.x = x - CollisionBox.w / 2; CollisionBox.y = y - CollisionBox.h / 2; XCenter = static_cast<float>(x); YCenter = static_cast<float>(y); }break; case PivotMode::TOP_LEFT: { CollisionBox.x = x; CollisionBox.y = y; XCenter = static_cast<float>(x) + CollisionBox.w / 2; YCenter = static_cast<float>(y) + CollisionBox.h / 2; }break; } } Paddle.h #pragma once #include "Entity.h" #include "GameMode.h" class GameMode; enum class PivotMode:Uint8; class Paddle : public Entity { public://methods Paddle(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path); ~Paddle(); virtual void Update(float deltaTime); virtual void Draw(float interpolation); }; GameMode.h #pragma once #include "SDL2\SDL.h" #include <string> #include <vector> #include <memory> #include "App.h" #include "Entity.h" #include "Paddle.h" class Entity; class Paddle; class GameMode { friend class App; private://variables bool Running; SDL_Window* Window; SDL_Renderer* Renderer; App* AppRef; public://constructors GameMode(SDL_Window* Window, SDL_Renderer* Renderer, App* App); ~GameMode(); GameMode(const GameMode&) = delete; GameMode& operator=(const GameMode&) = delete; GameMode(GameMode&&) = delete; GameMode& operator=(GameMode&&) = delete; public://methods SDL_Texture* RequestTexture(std::string path)const; bool IsRunning()const; SDL_Renderer* GetRenderer()const; private://methods void Update(float deltaTime); void Draw(float interpolation); };

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>