Right, the vector is copied like expected. There is a good software called geordi which can show this:
{
using namespace tracked;
typedef vector<B> poly_t;
poly_t poly(3); // contains 3 B's
vector<poly_t> v;
v.push_back(poly);
}
It tracks creation/copies of tracked::B
. Here is the output:
B0* B1*(B0) B2*(B0) B3*(B0) B0~ B4*(B1) B5*(B2) B6*(B3) B4~ B5~ B6~ B1~ B2~ B3~
This is output when we only track v.push_back
:
B4*(B1) B5*(B2) B6*(B3)
As you see, first B0 is created as the default argument of the vector constructor. Then that object is copied into 3 B's and after that B0 is destroyed again as the constructor comes back. poly then is created. Then, we push_back it into a vector of polygons. The argument, poly, is copied into a new vector which is created within the vector of polygons and managed by that.
If it crashes, the problem probably lies within another part of your program. Checks that the copy constructor/constructor and destructor work correctly and that they don't delete things twice if you use dynamic memory allocation.