Stl vector.push_back () abstract class does not compile

Say I have a stl vector containing a class like "xx". xx is abstract. I ran into a problem when the compiler does not allow me to "instantiate" when I do something like the following:

std::vector<xx> victor;
void pusher(xx& thing)
{
    victor.push_back(thing);
}

void main()
{
    ;
}

I guess this is because the copy constructor must be called. I ran into this problem by storing xx * in a vector, not in xx. Is there a better solution? What is it?

+3
source share
3 answers

push_back, . , , , .

, , boost loki.

+12

, (, , ), , STL, , , . , - . , , slicing.

+2

std::vector ( STL ) . , , . std::vector . , , , ( , , , , , , - boost:: noncopyable, , ).

0

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


All Articles