Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Created December 30, 2015 13:08
Show Gist options
  • Save alexaleluia12/2f52b143f15eab2d95be to your computer and use it in GitHub Desktop.
Save alexaleluia12/2f52b143f15eab2d95be to your computer and use it in GitHub Desktop.
error: cannot convert ‘std::vector<float*>’ to ‘float*’ in assignment
// I want to share a tricky thing that happened with me
// * I was programming in C style using feature of C++ (on g++)
// I have this structure
typedef struct {
vector<float *> * lst_vertices;
vector<int *> * lst_faces;
float referencia[3];// o ponto sobre o qual vai ser realizadas as transformacoes
} Obj3d;
// and a lot of functions like this
void desenhar_obj(vector<float *> & lst_vertices, vector<int *> & lst_faces);
// I pass 'vector<float *> * lst_vertices 'in this way
desenhar_obj(*ob->lst_vertices, *ob->lst_faces);
// And thing work file in those functions
// Then when I use lst_vertices direct
float *p1 = a1->lst_vertices[0];
// with the struct I get this error
// cannot convert ‘std::vector<float*>’ to ‘float*’ in assignment
// How to solve ?
// - 1
p1 = (float *) &(a1->lst_vertices)[0];
// - 2
p1 = a1->lst_vertices->operator[](0);
// ===
// Why
/*
lst_vertices is pointer so I need to user '->' operator
on the other function I pass lst_vertices by reference
and there I could use '[]'
float *p1 = lst_vertices[0];
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment