I have this class in my header render_object.hpp
:
class RenderObject {
public:
struct OGLVertexAttribute {
GLuint index;
GLint size;
GLenum type;
GLboolean normalized;
GLsizei stride;
void const *pointer;
};
public:
RenderObject(std::initializer_list<struct OGLVertexAttribute> attributes);
~RenderObject();
public:
void render();
public:
void updateIndices(std::vector<GLuint> &indices);
template<typename T>
void updateVertices(std::vector<T> &vertices);
private:
GLuint indexBuffer;
GLuint vertexArray;
GLuint vertexBuffer;
private:
unsigned int indexBufferSize;
};
I would like to make the updateVertices
function generic so that it can take vectors of any type (including tuples) so I defined a template for it.
template <typename T>
void RenderObject::updateVertices(std::vector<T> &vertices) {
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER,
vertices.size() * sizeof(T), &vertices[0], GL_DYNAMIC_DRAW);
}
However, when I compile, I get this linkage error:
/home/terminal/source/application.cpp:23: undefined reference to `void RenderObject::updateVertices<float>(std::vector<float, std::allocator<float> >&)'
Why is that and how can I fix it?