Когда вы делаете:
struct vertex2
{
vertex2(float *vertices);
private:
float *m_vertices;
public:
float *ConvertToFloatArray();
};
static float verts[] = { -0.5f, -0.5f,
0.5f, -0.5f,
0.5f, 0.5f,
-0.5f, 0.5f };
static game::data::vertex2 vertices = verts;
Вы объявляете статическую переменную с вершинами и передаете указатель на нее в конструкторе и ( мое предположение, потому что вы не включилиполный код ) сохраняющий указатель в вашем объекте.Если кто-то изменяет вершины, вершины в классе будут изменены (и аналогично, если вы измените свою вершину в классе, она изменит переменную вершин).
Но когда вы сделаете:
static game::data::vertex2 vertices = { -0.5f, -0.5f,
0.5f, -0.5f,
0.5f, 0.5f,
-0.5f, 0.5f };
Вы передаете список с плавающей точкой, а не указатель.
Вместо этого я предлагаю вам поиграть с этим: https://ideone.com/GVvL8y
#include <array>
class vertex2 // use class whenever possible, not struct
{
public:
static const int NUM_VERTICES= 6;
public:
// Now you can only init it with a reference to a 6 float array
// If you use float* you'll never know how many floats are there
constexpr vertex2(float (&v)[NUM_VERTICES])
: vertices{v[0], v[1], v[2], v[3], v[4], v[5]}
{
}
// Will take a list of numbers; if there's more than 6
// will ignore them. If there's less than 6, will complete
// with 0
constexpr vertex2(std::initializer_list<float> list)
{
int i= 0;
for (auto f= list.begin(); i < 6 && f != list.end(); ++f) {
vertices[i++]= *f;
}
while (i < NUM_VERTICES) {
vertices[i++]= 0;
}
}
constexpr vertex2() = default;
constexpr vertex2(vertex2&&) = default;
constexpr vertex2(const vertex2&) = default;
float* ConvertToFloatArray() const;
// Just for debugging
friend std::ostream& operator<<(std::ostream& stream, const vertex2& v)
{
stream << '{' << v.vertices[0];
for (int i= 1; i < vertex2::NUM_VERTICES; i++) {
stream << ',' << v.vertices[i];
}
return stream << '}';
}
private:
std::array<float, NUM_VERTICES> vertices{};
};