0

Error output:

C2065 : 'Shape':undeclared identifier | file: Scene.h

I searched around for an hour and I can't seem to solve this basic error. I'm lost a this point. I'm sure It's something basic and I'm going to get -1 for it, but I really don't see the problem.

Scene.h

#pragma once

#include <vector>
#include <memory>
#include "Shape.h"

class Scene {
protected:
    std::vector<std::unique_ptr<Shape>> m_shape_ptrs; // <<<<< HERE
    //std::vector<std::shared_ptr<Light>> m_light_ptrs;

public:


    inline Shape& get_shape(int i) { return *m_shape_ptrs[i].get(); }
    std::pair<Shape*, float> intersect(const Ray& ray) const;
};

Shape.h

#pragma once

#include "Ray.h"
#include "Vector.h"
#include "Material.h"

class Shape {
public:
    Material material;

    virtual float intersect(const Ray& ray) const = 0;
    virtual Vec3f get_normal(const Vec3f& p) const = 0;
};

Material.h

#pragma once

#include "bitmap.hpp"
#include "Renderer.h"
#include "Shape.h"  // <<< HERE IT IS A CIRCULAR DEPENDENCY
#include "Ray.h"

class Material {
public:
    enum class TYPE : unsigned char
    {
        NULL_MATERIAL =  0,
        MIRROR,
        TRANSPARENT,
        PHONG,
        DIFFUSE
    };

    TYPE type;

    rgb_t get_color(const Shape& shape, const Ray& incident, const Renderer& renderer) const;
};
Angramme
  • 164
  • 1
  • 10
  • 1
    Make sure that none of these `#include "Ray.h" #include "Vector.h" #include "Material.h"` include Shape.h – drescherjm Jun 18 '19 at 19:09
  • 2
    Most probably something along the lines of [Resolve build errors due to circular dependency amongst classes](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes). – πάντα ῥεῖ Jun 18 '19 at 19:11
  • 1
    In `Scene.h` you don't appear to need to include `Shape.h` a forward declaration would suffice. – drescherjm Jun 18 '19 at 19:12
  • Well aparently I forgot about circular dependency, thanks! – Angramme Jun 18 '19 at 19:12

0 Answers0