努力学习的小小周 2023-01-18 20:08 采纳率: 75%
浏览 20
已结题

OpenGL学习报错

代码如下:

#include <vector>
#include <GL/glew.h>

struct VertexBufferElement
{
    unsigned int type;
    unsigned int count;
    bool normalized;
};

class VertexBufferLayout
{
private:
    std::vector<VertexBufferElement> m_Elements;
    unsigned int m_Stride;
public:
    VertexBufferLayout()
        :m_Stride(0) {}

    template<typename T>
    void Push(int count)
    {
        static_assert(false);
    }

    template<>
    void Push<float>(int count)
    {
        m_Elements.push_back({GL_FLOAT, count, false});
        m_Stride += sizeof(GLfloat);
    }

    template<>
    void Push<unsigned int>(int count)
    {
        m_Elements.push_back({GL_UNSIGNED_INT, count, false });
        m_Stride += sizeof(GLuint);
    }

    template<>
    void Push<unsigned char>(int count)
    {
        m_Elements.push_back({GL_UNSIGNED_BYTE, count, true });
        m_Stride += sizeof(GLbyte);
    }

    inline const std::vector<VertexBufferElement>GetElements() const { return m_Elements; }
    inline unsigned int    GetStride() const { return m_Stride; }
};

报错
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0304 没有与参数列表匹配的 重载函数 "std::vector<_Ty, _Alloc>::push_back [其中 _Ty=VertexBufferElement, _Alloc=std::allocator]" 实例 OpenGL E:\opengl\1\Opengl\src\VertexBufferLayout.h 30

  • 写回答

2条回答 默认 最新

  • 流比 2023-01-18 21:14
    关注

    这个错误提示说,在第30行的代码中调用了 std::vector 的 push_back 函数,但是没有找到与参数列表匹配的重载函数。这可能是因为你在调用 push_back 函数时传入的参数类型不正确。

    看你的代码,你是用模板函数Push()来实现的,在这里你需要注意你是否传入了正确的类型,再检查一下你的 vector 类型是否正确。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月1日
  • 已采纳回答 1月24日
  • 创建了问题 1月18日

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法