glGenBuffers (Exception has occured)

So i am trying to draw a triangle as a test for my game but when i try to run the game i get this result:

This is my Triangle.cpp:

#include <GL/glew.h>

#include "VertexBuffer.h"
#include "Triangle.h"

Triangle::Triangle()
{
    float positions[] = {
        -0.5f, -0.5f,
         0.0f,  0.5f,
         0.5f, -0.5f
    };

    glGenBuffers(1, &buf);
    glBindBuffer(GL_ARRAY_BUFFER, buf);
    glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
    glEnableVertexAttribArray(0);
}

I don’t really understand what the problem is. Is there any fix?

Have you created a GL context?
Is it bound and active?

https://glew.sourceforge.net/basic.html

sounds like you are creating a “triangle object” before “glewinit()” has been called
by the way, its not really a good idea to wrap gl code in the constructor of a class

No, constructors are fine. As long as you don’t try to create those objects statically before main and your GL initialization code.