0

I'm learning to use OpenGL and refresh my knowledge of C++. I want to make simple way to render objects with one call, I've created Mesh class (that inherits from Component but that doesn't matter) and it should have 2 public variables (for now) which is float array for vertices and unsigned int array for indices, however when I try to create them in .h like this:

#pragma once

#include "../Component.h"

class Mesh : public Component {

public:
    float vertices[]; //error is on this line of code
    unsigned int indices[];

    Mesh(float vertices[], unsigned int indices[]);

};

it gives me a error which says "Incomplete type is not allowed", however this only happens if there are 2 arrays, if I remove the unsigned int array it works, then if unsigned int array would be declared one line higher like this:

public:
    unsigned int indices[]; //now the error is here
    float vertices[];

    Mesh(float vertices[], unsigned int indices[]);

and I remove the float array, then there is no error, I tried everything, and it can't be problem with that there is no size specified because if I remove the other array it magically works. Also sorry if this is like simple mistake I haven't worked with C++ in long time.

Cheers.

  • Please show a [mre] – Ted Lyngmo Jul 04 '21 at 20:49
  • `float vertices[];` you have to give the array a size. Also this type of array will be a fixed size at compile time. It can not change size at runtime. – drescherjm Jul 04 '21 at 20:49
  • 1
    *I haven't worked with C++ in long time.* -- I suggest you learn the basics of C++ first before using libraries like OpenGL, which assume you know the programming language you're using. – PaulMcKenzie Jul 04 '21 at 20:57
  • 1
    *"it can't be problem with that there is no size specified"* -- and yet, that is the problem (combined with another factor, specifically that [there is a data member after it](https://stackoverflow.com/a/26614576)). Sometimes it pays to question your assumptions. – JaMiT Jul 04 '21 at 21:25
  • "flexible array members" search term – Jeffrey Jul 04 '21 at 22:17
  • "it can't be problem with that there is no size specified because if I remove the other array it magically works" Only the last member of a class is allowed to not have a size specified. – Joseph Sible-Reinstate Monica Jul 05 '21 at 00:39

0 Answers0