Sort of, except for the fundamental problem of not knowing what sizeof is actually capable of doing.
For example, sizeof has nothing to do with scope.
Code:
float vertices[] = { // no new
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
// This is fine
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// This is broken
float *pVertices = vertices;
glBufferData(GL_ARRAY_BUFFER, sizeof(*pVertices), pVertices, GL_STATIC_DRAW);
It has NOTHING to do with the scope of pVertices, or whether pVertices points to a local array or some block of heap memory.
You would also run into the same problem if you passed the array (in either incarnation) from one function to another function, before passing it onto glBufferData.
These on the other hand would work in both cases.
Code:
float vertices[] = { // no new
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
// This is fine
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * 9, vertices, GL_STATIC_DRAW);
// This is fine too :)
float *pVertices = vertices;
glBufferData(GL_ARRAY_BUFFER, sizeof(pVertices[0]) * 9, pVertices, GL_STATIC_DRAW);
But as Guest demonstrates, there are better C++ ways of creating array like objects.