I have Vector class, representing a 3D point, written as follows in Vector.h:
class Vector {
public:
float x,y,z;
Vector(float _x=0.0,float _y=0.0,float _z=0.0){x=_x;y=_y;z=_z;};
operator float *() { return &x;};
};
I also declare a extern vector<Vector>model_vertices; on model.h
On a model.cpp file I implement Vector.h and declare a std::vector<Vector>model_vertices; globally (yes, I know the vector/Vector thing is confusing, but I must use the Vector naming for consistency).
On model.cpp, when initializing the contents of this vector I use a for loop with the following content:
float X,Y,Z;
offFileStream>>X;
offFileStream>>Y;
offFileStream>>Z;
Vector v=new Vector(X,Y,Z);
model_vertices[loadVertexIndex]=v;
I get the following error:
error C2440: 'initializing' : cannot convert from 'Vector *' to 'Vector'
Why?
The error is on this line:
vis of typeVector, butnew Vector(X,Y,Z)returns aVector*:What you probably wanted instead is just:
As a side note, I didn’t see you initialize a size for the
model_vertices. So you may want to usepush_back()instead.