c++ - '转换': 'class' OpenGL 3D type redefinition

标签 c++ compiler-errors redefinition multiple-definition-error

我收到此编译错误:

Error: 'Transform': 'class' OpenGL 3D type redefinition on line 5



这是我的Transform.h:
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>

class Transform
{
public:
    Transform(const glm::vec3& pos = glm::vec3(), const glm::vec3& rot = glm::vec3(), const glm::vec3& scale = glm::vec3(1.0f, 1.0f, 1.0f)) :

    Pos(pos),
    Rot(rot),
    Scale(scale) {}

    inline glm::mat4 GetModel() const
    {
        glm::mat4 posMatrix = glm::translate(Pos);
        glm::mat4 rotXMatrix = glm::rotate(Rot.x, glm::vec3(1,0,0));
        glm::mat4 rotYMatrix = glm::rotate(Rot.y, glm::vec3(0,1,0));
        glm::mat4 rotZMatrix = glm::rotate(Rot.z, glm::vec3(1,0,0));
        glm::mat4 scaleMatrix = glm::scale(Scale);

        glm::mat4 rotMatrix = rotZMatrix * rotYMatrix * rotXMatrix;

        return posMatrix * rotMatrix * scaleMatrix;
    }

    inline glm::vec3& GetPos() { return Pos;  }
    inline glm::vec3& GetRot() { return Rot;  }
    inline glm::vec3& GetScale() { return Scale; }

    inline void SetPos(glm::vec3& pos) { Pos = pos; }
    inline void SetRot(glm::vec3& rot) { Rot = rot; }
    inline void SetScale(glm::vec3& scale) { Scale = scale;  }
protected:
private:
    glm::vec3 Pos;
    glm::vec3 Rot;
    glm::vec3 Scale;
};

我正在关注来自thebennybox的本教程系列:

https://www.youtube.com/watch?v=Xe7FmplKAF0&t=419s

我正在使用带有C++和OpenGL的Visual Studio Community 2015。

是什么导致该错误,我该如何解决?

最佳答案

您要在头文件中添加包含保护。检查此链接:cplusplus.com/forum/general/71787

关于c++ - '转换': 'class' OpenGL 3D type redefinition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42640454/

相关文章:

c# - 使用 Swig 为 C++ 代码构建 C# 包装器时,是否可以向现有方法添加代码?

c++ 到 vb.net,回调函数的问题

c++ - 无法识别的命令行选项 '-std=c++11'

c++ - 模板参数中的 enable_if 创建模板重新定义错误

c - 如何设置 Eclipse gcc 编译器忽略特定错误或从错误更改为警告

c++ - 在 main : Inline versus non-inline functions 中包含 cpp 文件时出现编译错误

c++ - qss中设置QTreeView选中项样式

c++ - 内联函数和 __thiscall __cdecl Bjarne String 示例

c++ - 错误 C2065 : 'resultImgs' : undeclared identifier

node.js - 我在npm run dev时遇到错误而没有提示