For the code below, I would like to know how to set std::shared_ptr
to point the given objects in the two member functions. The Vector3
object which is allocated in the main function is not going to be deleted until the end of the program.
#include <memory>
#include <vector>
using std::vector;
using std::shared_ptr;
class Vector3
{
// ...
};
class Face
{
vector < shared_ptr <Vector3> > vtx;
public:
void addVtx (const Vector3& vt)
{
// vtx.push_back (); <-- how to push_back ?
}
void setVtx (const int v, const Vector3& vt)
{
if ( vtx.size() > 0 && v < vtx.size() )
{
// vtx[v] = &vt; <-- how to assign ?
}
}
};
int main ()
{
vector <Vector3> vec (3);
Face face;
face.addVtx (vec[0]);
face.setVtx (0, vec[0])
return 0;
}