Huh?
m_Mesh = (ID3DXMesh*)&meshm_Mesh = mesh;
Assuming that m_Mesh and m_Mesh are both of type ID3DXMesh*, the first line is a horrible, horrible thing to do.
&mesh will return the address of the pointer, so is type ID3DXMesh** (pointer to pointer).
Doing a C-style cast (in this case, effectivly a reinterpret_cast) from ID3DXMesh** to ID3DXMesh* will cause undefined behaviour.
But then the next line overwrites m_Mesh with mesh anyway.
What is probably happening is this:
void f(ID3DXMesh *&mesh){ m_Mesh=mesh; // m_Mesh now points to same place as mesh D3DXCreateMeshFVF(blah,blah,&m_Mesh); // m_Mesh now points to different place than mesh CreateMesh(100,100); // item mesh points to is unaffected}// function returns. What m_Mesh points at is unrelated to what mesh points at
If you really need to store the mesh in the class, you need to do this:
class Converter{private: ID3DXMesh *&m_Mesh;public: Converter(ID3DXMesh *&mesh) : m_Mesh(mesh) { }};
Since m_Mesh is a reference, it must be initialised in the constructor initialiser list. It is, however, now a true alias for mesh.
The design is silly though. Why pass the mesh into the Converter? Why not have Converter do all its work on its own mesh pointer then return the mesh pointer via a:
ID3DXMesh *Converter::GetMesh(){ return m_Mesh; }
method? You can then create your Converter, do all the work, then assign to your external mesh pointer from this method.
ID3DXMesh *mesh;void f(){ Converter c; c.Init("model.x"); mesh=c.GetMesh();}
But then why can't Init's code be in the constructor?
void f(){ Converter c("model.x"); mesh=c.GetMesh();}
You don't really need to store the mesh inside the Converter class anyway.
class Converter{private: void CreateMesh(const std::string &file,ID3DXMesh *&mesh){ /* do stuff */ } void DecorateMesh(ID3DXMesh *mesh){ /* do stuff */ }public: Converter(const std::string &file,ID3DXMesh *&mesh);};Converter::Converter(const std::string &file,ID3DXMesh *&mesh){ CreateMesh(file,mesh); DecorateMesh(mesh);}ID3DXMesh *mesh;void f(){ Converter c("model.x",mesh);}