简体   繁体   中英

XCode & Clang do not recognize a class of mine despite proper include

Hey guys I have some class

//
//  renderGUI.h
//  raytracer
//
//  Created by Noah on 24/01/14.
//  Copyright (c) 2014 syx. All rights reserved.
//

#ifndef raytracer_renderGUI
#define raytracer_renderGUI

#include <SFML/Graphics.hpp>
#include <SFGUI/SFGUI.hpp>
#include <renderer.h>

class RenderGUI{

private:
    Renderer* renderer;
    std::shared_ptr<sfg::Window> window;
    std::shared_ptr<sfg::Button> render;
    std::shared_ptr<sfg::Button> abort;
    std::shared_ptr<sfg::ProgressBar> progress;
    std::shared_ptr<sfg::CheckButton> antialiasing;
    void OnComboSelect();
    void startRenderThread();
    void endRenderThread();
    unsigned int renderButtonEvent;

public:
    RenderGUI(Renderer* renderer);
    sfg::Window::Ptr getWindow();
    void update();
    void updateProgressBar(double progress);
    void renderScene();
};


#endif

and here is the renderer.h:

//
//  renderer.h
//  raytracer
//
//  Created by Noah on 31/01/14.
//  Copyright (c) 2014 syx. All rights reserved.
//

#ifndef raytracer_renderer
#define raytracer_renderer

#include <scene.h>
#include <thread>

class Renderer{

private:
    sf::Texture* texture;
    sf::Uint8* canvas;
    Vector resolution;

    Scene* scene;
    MaterialManager* materialManager;
    Camera* camera;

    bool canvasReady;
    bool antiAliasing;
    bool canRender;

    double progress;
    std::thread renderThread;

    Color traceRay (const Ray& ray, double, int iter) const;

    void setPixel(int x, int y, Color c);

public:
    Renderer(Scene *scene, MaterialManager *materialManager, Vector resolution, bool antiAliasing);

    sf::Texture* getTexture();
    sf::Uint8* readCanvas();
    double epsilon;
    void update();
    void render();
    void useAntiAliasing(bool antiAliasing);
    bool useAntiAliasing();
    bool isCanvasReady();
    void chooseCamera(Camera* camera);
    void startRenderThread();
    void endRenderThread();
    double getProgress() const;
};

#endif

But now my compiler tells me "Projects/ETH/ETH/raytracer/raytracer/renderGUI.h:19:5: Unknown type name 'Renderer'; did you mean 'sfg::Renderer'?" on line 19 and 31 even tho in my opinion it should find my class ...

Can anyone give me some hint? Thanks in advance!

Peace

Without seeing your scene.h header file I'm guessing circular inclusion. The renderGUI.h header file includes the render.h header file which (probably indirectly) includes renderGUI.h .

In this case it's pretty simple to solve: Don't include render.h in renderGUI.h , only declare the Renderer class.

So the renderGUI.h file looks something like

#ifndef raytracer_renderGUI
#define raytracer_renderGUI

#include <SFML/Graphics.hpp>
#include <SFGUI/SFGUI.hpp>

class Renderer;

class RenderGUI{

private:
    Renderer* renderer;
    ...
};

#endif

The reason this work is because you only use a Renderer pointer in the definition of the RenderGUI class, so it's enough that the compiler knows that there is a class existing with the name Renderer , the compiler doesn't need to know more information about that class.

Of course, in the source file where you actually work with instances (or pointers to instances) of the Renderer class you need the full definition, so there you should include the header file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM