![](/img/trans.png)
[英]C++ Error: "There are no arguments to 'setw' that depend on a template parameter
[英]How to fix 'there are no arguments to 'glGenVertexArrays' that depend on a template parameter …' error in c++
我有一个带有多个unsigned int的T*
和5函数的模板类,仅声明了其中一个,该类在.h文件中创建,最后它包含一个.tcc文件,将在其中声明其余的4个函数,在GenerateBuffer
函数中,我使用多个OpenGL调用,并且所有这些调用均给出相同的错误, there are no arguments to 'glGenVertexArrays' that depend on a template parameter, so a declaration of 'glGenVertexArrays' must be available
我曾经在.cpp文件中包含函数声明,而不是在.h文件末尾包含.cpp文件,而在开头包含.h文件,它没有给出任何错误,但是在尝试调用函数时它会给出一个未声明的链接错误,目前我有这个
#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
在头文件中,我尝试也将其放在.tcc文件的开头,但是我遇到了相同的错误,尝试了两个相同的错误。 我针对此错误在线找到的唯一解决方案是包括有问题的文件,但我始终拥有这些文件,或者using namespace
进行添加,但glGenVertexArrays不是任何命名空间的一部分,也不是我的课程
头文件
#ifndef _VERTEXBUFFER_
#define _VERTEXBUFFER_
#include "../Core/Settings.h"
template<typename T> class VertexBuffer {
public:
unsigned int BufferId;
unsigned int IndexId;
unsigned int VAO;
T* Vertices;
unsigned int* Indexs;
int DrawCount() { return (Indexs != nullptr) ? sizeof(Indexs) / sizeof(Indexs[0]) : sizeof(Vertices) / sizeof(Vertices[0]);}
void GenerateBuffer(T data[]);
void SetIndexData(unsigned int data[]);
void Bind();
void UnBind();
};
#include "VertexBuffer.tcc"
#endif
有问题的功能
template<typename T> void VertexBuffer<T>::GenerateBuffer(T data[]) {
Vertices = data;
if (Settings::Engine == OpenGL) {
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &BufferId);
glBindBuffer(GL_ARRAY_BUFFER, BufferId);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), Vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(data[0]), 0);
}
}
与您的实际问题稍有关系,但是恕我直言,它太重要了,不能只在注释中添加:您以一种幼稚的方式使用了sizeof
运算符:
template<typename T> void VertexBuffer<T>::GenerateBuffer(T data[]) { glBufferData(…, sizeof(data), …, …);
那样行不通。 您会看到, sizeof
返回传递给它的表达式结果的大小。 写入sizeof(1+2)
同样有效。 那么data
的大小是多少? 当然,表达式data
结果的大小也是如此。 假定数据是数组函数参数(而不是实际的数组对象),则表达式data
会衰减为指针,因此sizeof(data)
告诉您指针的大小,而不是数组的大小!
我只是在这里指出这一点,因为一旦解决了原始问题,毫无疑问,您会陷入这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.