the_subset is a local variable which will go out of scope when returning from the function random_subset. You either need to add a reference to m2 as a parameter to the call or return a mesh allocated on the heap:

Mesh<3>* random_subset( Mesh<3> const& mesh, unsigned int size )

{

Mesh<3>* the_subset = new Mesh<3>[size];

// Use STL random sample algorithm to pick points:

Vertex<3> temp_holder[size];

Mesh<3>::Const_Vertex_Iterator first_vertex = mesh.const_vertices().first;

Mesh<3>::Const_Vertex_Iterator last_vertex = mesh.const_vertices().second;

__gnu_cxx::random_sample_n( first_vertex, last_vertex,

temp_holder, size );

for (unsigned int i = 0; i < size; ++i)

{

the_subset->add_vertex( temp_holder[i] ); // Here, vertices are copied to the new Mesh.

}

return the_subset;

}

And don't forget to delete [] the returned value when it is no longer used.

} // end namespace ICP_Tools

Mesh<3>* random_subset( Mesh<3> const& mesh, unsigned int size )

{

Mesh<3>* the_subset = new Mesh<3>[size];

// Use STL random sample algorithm to pick points:

Vertex<3> temp_holder[size];

Mesh<3>::Const_Vertex_Iter

Mesh<3>::Const_Vertex_Iter

__gnu_cxx::random_sample_n

temp_holder, size );

for (unsigned int i = 0; i < size; ++i)

{

the_subset->add_vertex( temp_holder[i] ); // Here, vertices are copied to the new Mesh.

}

return the_subset;

}

And don't forget to delete [] the returned value when it is no longer used.

} // end namespace ICP_Tools