代码如下:
#include
#include
struct VertexBufferElement
{
unsigned int type;
unsigned int count;
bool normalized;
};
class VertexBufferLayout
{
private:
std::vector 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::vectorGetElements() 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
这个错误提示说,在第30行的代码中调用了 std::vector 的 push_back 函数,但是没有找到与参数列表匹配的重载函数。这可能是因为你在调用 push_back 函数时传入的参数类型不正确。
看你的代码,你是用模板函数Push()来实现的,在这里你需要注意你是否传入了正确的类型,再检查一下你的 vector 类型是否正确。