【问题标题】:template-id does not match any template declaration GNU gcc compiler模板 ID 不匹配任何模板声明 GNU gcc 编译器
【发布时间】:2019-07-27 07:49:58
【问题描述】:

我正在尝试创建一个 openGL 程序。我只在这个头文件中得到错误。错误是“error: template-id 'method' for 'void VertexBufferLayout::method(unsigned int)' does not match any template declaration”我不知道该怎么做。

我尝试过,但类中的模板没有成功。

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

    public:
    template <typename T>
    void method(T obj)
   {
//       static_assert(false);
    }

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

template<>
void VertexBufferLayout::method<float>(unsigned int count)
{
    VertexBufferLayout::m_Elements.push_back({ GL_FLOAT, count, false });
    VertexBufferLayout::m_Stride += VertexBufferElement::GetSizeOfType(GL_FLOAT);
}

template<>
void VertexBufferLayout::method<unsigned int>(unsigned int count)
{
    VertexBufferLayout::m_Elements.push_back({ GL_UNSIGNED_INT, count, false });
    VertexBufferLayout::m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT);
}

template<>
void VertexBufferLayout::method<unsigned char>(unsigned int count)
{
    VertexBufferLayout::m_Elements.push_back({ GL_UNSIGNED_BYTE, count, true });
    VertexBufferLayout::m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE);

}  

错误是“error: template-id 'method' for 'void VertexBufferLayout::method(unsigned int)' does not match any template declaration”

【问题讨论】:

    标签: c++ templates gcc compiler-errors


    【解决方案1】:

    这里是什么类型的Tfloat 还是unsigned int

    VertexBufferLayout::method<float>(unsigned int count)
    

    这是典型的复制粘贴错误。我想应该是

    VertexBufferLayout::method<float>(float count)
    

    后面的行有同样的错误

    void VertexBufferLayout::method<unsigned char>(unsigned int count)
    

    必须

    void VertexBufferLayout::method<unsigned char>(unsigned char count)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多