C++ Calling Private Constructor in Own Class
Im Using Vcg Library I Have a Private Constructor Since Trimesh Can't Be Copied in My Header File Myprocessing. H Class Mymesh: Public Vcg: :Tri: :Trimesh<...
Im using VCG library I have a private constructor since Trimesh cant be copied in my header file MyProcessing.h
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> ,
std::vector<MyEdge> > {
private:
MyMesh(const TriMesh &mesh);
MyMesh operator= (const TriMesh &mesh);
};
And I have a lot of trouble calling it in my MeshProcessing.cpp file What im trying to do is create My mesh in there This is what ive tried
vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > *t_mesh;
MyMesh vcgMesh =MyMesh::MyMesh(*t_mesh);
but compiler is copmplaining abou inaccesible element
Any help how to create it will be appreciated
EDIT1
private:
// TriMesh cannot be copied. Use Append (see vcg/complex/append.h)
TriMesh operator =(const TriMesh & /*m*/){assert(0);return TriMesh();}
TriMesh(const TriMesh & ){}
}; // end class Mesh
2 Answers
Because the given constructor and assignment operator are private, you can only use them within member functions of MyMesh or its friend classes. You get a compiler error because
MyMesh vcgMesh =MyMesh::MyMesh(*t_mesh);
is not in a member function of MyMesh or any of its friends.
You will need to make a public constructor or some factory class to solve your problem.
You can't call them outside of the class because you've made them private.
It sounds like you don't want to restrict access, so just make them public :
public:
MyMesh(const TriMesh &mesh);
MyMesh operator= (const TriMesh &mesh);
and provide an appropriate implementation.