0

I have this structure in c++:

struct Vertex_2 {
    GLdouble position[3];
};

I am trying to access the array inside of it like this:

Vertex_2.position[0] = //something;
Vertex_2.position[1] = //something;
....
...
..

when I compile it I get this:

error: expected unqualified-id before ‘.’ token

why is that?

3 Answers 3

2

You have to create an instance of the struct before using the members thereof.

Vertex_2 v; // v is an *instance* of the *struct* Vertex_2
v.position[0] = //something;
v.position[1] = //something;
...

Think of Vertex_2 as a description of what all Vertex_2's should look like (but it is not, itself, a Vertex_2). Then you have to actually create a Vertex_2, by doing Vertex_2 name;. In the example, we used the name v instead of name, but you can name the instance whatever you want. Then you can access the member variables of that instance through the name with a dot (.), like you tried to do before.

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

Comments

1

You need to define a variable of your class, you only defined a type.

struct Vertex_2 {
    GLdouble position[3];
} varVertex_2; // <-- now you have an instance of the struct


varVertex_2.position[0] = //something;
varVertex_2.position[1] = //something;

Comments

0

Because you are trying to access struct type not the actual struct. Try:

struct Vertex_2 {
    GLdouble position[3];
} myVertex;

myVertex.position[0] = //something;
myVertex.position[1] = //something;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.