Clicking vectors vectors

Is there something wrong with dropping a vector of vectors? as

typedef vector<Point> Polygon;
vector<Polygon> polys;
polys.push_back(some_poly);

Will all elements in some_poly be copied correctly?

I have an error in my code and I canโ€™t understand what is wrong with it.

+3
source share
4 answers

Yes, this should work fine if you define a copy constructor and assignment operator for your Point class (and make sure they do the right thing, etc.). std :: vector will be just fine, so the error should be in a different place - obviously, we will need additional information to help further.

, , , ( , ).

+2

, . geordi, :

{ 
    using namespace tracked; 
    typedef vector<B> poly_t; 
    poly_t poly(3); // contains 3 B's
    vector<poly_t> v; 
    v.push_back(poly); 
}

/ tracked::B. :

B0* B1*(B0) B2*(B0) B3*(B0) B0~ B4*(B1) B5*(B2) B6*(B3) B4~ B5~ B6~ B1~ B2~ B3~

, v.push_back:

B4*(B1) B5*(B2) B6*(B3)

, B0 . 3 B B0 , . poly. . , poly, , .

, , , . , / , .

+6

. /, .

/, , , :

typedef vector<Point> Polygon;
typedef vector<Polygon*> Polygons;
Polygons polys;
polys.push_back(new Polygon());
+2

Although there are no vector vectors, you can look at Boost.MultiArray . It may be more effective.

 typedef boost::multi_array<Point, 2> Polygons;

Another idea is that you can make Polygon a real class (possibly containing a vector) to provide more tailored methods than those provided by default with std :: vector.

+1
source

Source: https://habr.com/ru/post/1705218/


All Articles