I'm trying to learn C++ and have hit a compile error that I cannot figure out how to fix. I'm sure that it is something simple I've missed but I can't work it out at all.
Display.cpp:21:17: error: ‘Renderer’ was not declared in this scope
std::shared_ptr<Renderer> Display::CreateRenderer(std::shared_ptr<Window> windo
^
The Renderer.h file is included in the Display.h file, so from what I understand it should be picking it up (it should not need to be forward declared, as that is done by the #include in effect?). I've tried providing the full namespace but that had no effect. What confuses me is that the other file I've included (Window.h) works fine, and if I remove the GetRenderer() function it compiles with no errors. The only real difference between the Window and the Renderer class is that Renderer has a #include of another class (texture), but as far as I can tell there are no cyclic dependencies.
Here are the files involved:
Display.h
#include <SDL2/SDL.h>
#include <iostream>
#include <memory>
#include "Window.h"
#include "Renderer.h"
#ifndef DISPLAY_H
#define DISPLAY_H
namespace MapTool {
namespace Display {
class Display {
public:
Display();
~Display();
std::shared_ptr<Window> CreateWindow(std::string title,
int openX, int openY,
int width, int height);
std::shared_ptr<Renderer> CreateRenderer(std::shared_ptr<Window> window);
private:
};
}
}
#endif
Display.cpp
#include "Display.h"
using namespace MapTool::Display;
Display::Display() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "SDL Initialisation failed " << SDL_GetError() << std::endl;
}
}
Display::~Display() {
SDL_Quit();
}
std::shared_ptr<Window> Display::CreateWindow(std::string title,
int openX, int openY,
int width, int height) {
return std::shared_ptr<Window>(new Window(title, openX, openY, width, height));
}
std::shared_ptr<Renderer> Display::CreateRenderer(std::shared_ptr<Window> window) {
return std::shared_ptr<Renderer>(new Renderer(window->GetWindow()));
}
Any pointers on what I'm missing would be much appreciated. I feel it might be because I'm not too sure about header files, so if this is due to fundamental misunderstanding of how to use them then any pointers to good resources would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire