I have structure like this:
struct Rz3DContourNode {
float x;
float y;
float z;
float nx;
float ny;
float nz;
};
And I store elements in a STL vector as follows :
std::vector < Rz3DContourNode > nodes;
Now I want to change the nx,ny compoent of the nodes in the vector.I tried as follows:
*(&nodes[i].nx)=newNXValue;
*(&nodes[i].ny)=newNYValue;
*(&nodes[i].nz)=newNZValue;
This did not work.Is it because nodes[i] returns a copy of the object?
Is there any solution for this expect using pointers ?
I cannot use pointer (Rz3DContourNode*) , because I am using this vector in OpenGL as
glNormalPointer(GL_FLOAT,sizeof(Rz3DContourNode), &nodes[0].nx);
EDIT – I am sorry.I actually keep a QList and get the std::vector everytime.That was the reason
std::vector<Rz3DContourNode> nodeVector = nodes.toVector().toStdVector();
It works on my compiler….
Taking the address of the instance and then dereferencing it is the same as not doing it all.
So you don’t need it. So replace this
with
Here is the code sample I tried: