0

Hi I've been asked to set my arrays that contain 3d cube information to "null" so that they can be used to take in the data that is required to draw them from a txt file but have run int this error.

Any help would be appreciated.

cube header file

class Cube { private: static int numVertices, numColours, numIndices; static Vertex indexedVertices[]; static Color indexedColors[]; static GLushort indices[]; GLfloat _rotation; GLfloat _CubeX; GLfloat _CubeY; GLfloat _CubeZ; 

Cube cpp file

 Vertex *Cube::indexedVertices = nullptr; Color *Cube::indexedColors[] = nullptr; GLushort *Cube::indices[] = nullptr; 

The error appears under indexedVertices , indexedColors and indices

2
  • 2
    Arrays are not pointers, and thus cannot be initialized to nullptr. Commented Feb 20, 2014 at 7:05
  • 4
    Use std::array or std::vector and stop worrying about this kind of stuff. Commented Feb 20, 2014 at 7:06

1 Answer 1

2

Arrays can't be null.

Also, you didn't specify the size of the arrays in their definitions.

Also, your definitions don't match your declarations! Compare:

static Vertex indexedVertices[]; // declares an array of Vertexes Vertex *Cube::indexedVertices = nullptr; // defines a pointer to a Vertex 

Also compare:

static Color indexedColors[]; // declares an array of Colors Color *Cube::indexedColors[] = nullptr; // defines an array of pointers to Colors 

Arrays are not pointers. Sometimes the language will "helpfully" convert arrays to pointers for you (e.g. indexedVertices is converted to &indexedVertices[0] when used in an expression), but they are not the same thing!

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the help. As you said I did think that it was strange to set an array to a null pointer but thought as I'm new to C++ maybe there was a way to do it. Here is what I was asked to do: There are a few steps we have to take to convert our Cube into one that is loaded from the file. However, first we can get rid of the existing data stored within the cube class. In your cube.cpp file, change the arrays implemented at the top of the file to contain no data. Vertex* Cube::indexedVertices = nullptr; Color* Cube::indexedColors = nullptr; GLushort* Cube::indices = nullptr;
@user3331499 Notice that those are not arrays.
What would you suggest in order to fix this? I don't understand why it wants me to set the array to a nullptr when I haven't declared it as a pointer.
I thought your assignment said to change the arrays to pointers?
I've got it working now thank you for all of the help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.