首页 > 解决方案 > C2065 未声明标识符但没有明显原因

问题描述

错误输出:

C2065:“形状”:未声明的标识符 | 文件:Scene.h

我搜索了一个小时,似乎无法解决这个基本错误。我失去了这一点。我确定这是基本的东西,我会得到-1,但我真的看不出问题。

场景.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;
};

形状.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;
};

材料.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;
};

标签: c++

解决方案


推荐阅读