I am rewriting the mouse input tutorial on lazyfoo.net to use headers and cpp files instead of putting everything in one cpp file. I am doing this just for practice. I am running Windows 10 and I am using Code::Blocks 16.01 on a Dell laptop.
When I compile the following source code I get an error message that says "expected class name before '{' token" in my ltexture.h file. I have tried forward declaring CentralClass in my ltexture.h file and when I do that I get an error message that says "invalid use of incomplete type 'class CentralClass'". I have also looked up several answers to this same question on this website but nothing seems to work.
Here is the code.
ltexture.h
#ifndef LTEXTURE_H_INCLUDED
#define LTEXTURE_H_INCLUDED
#include <string>
#include "central_class.h"
class LTexture : public CentralClass
{
// The actual hardware texture
SDL_Texture *mTexture;
// Image dimensions
int mWidth;
int mHeight;
public:
// Initialize variables
LTexture();
// Deallocates memory
~LTexture();
// Loads image at specified path
bool loadFromFile(std::string path);
// Deallocates texture
void free();
// Renders texture at given point
void render(int x, int y, SDL_Rect *clip = nullptr, double angle = 0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
// Gets image dimensions
int getWidth() {return mWidth;}
int getHeight() {return mHeight;}
};
#endif // LTEXTURE_H_INCLUDED
central_class.h
#ifndef CENTRAL_CLASS_H_INCLUDED
#define CENTRAL_CLASS_H_INCLUDED
#include <SDL.h>
#include "lButtonSprite.h"
#include "lbutton.h"
#include "ltexture.h"
#include "global.h"
class CentralClass
{
// The window we'll be rendering to
SDL_Window *mWindow;
// Button objects
LButton mButtons[global::TOTAL_BUTTONS];
protected:
// The window renderer
SDL_Renderer *mRenderer;
// Mouse button sprites
SDL_Rect mSpriteClips[button::TOTAL];
LTexture mButtonSpriteSheetTexture;
public:
// Call all functions
CentralClass();
// Starts up SDL and creates window
bool init();
// Loads media
bool loadMedia();
// Main part of the program
void mainLoop();
// Frees media and shuts down SDL
void close();
// Clean up
~CentralClass();
};
#endif // CENTRAL_CLASS_H_INCLUDED
Both of these classes depend on eachother. Please help get rid of these errors. I don't know what to do.enter code here