简体   繁体   中英

C++ STL list size

i've got some problem/ i don't understand something and it cause this problem :)

Here is some code:

list<Walec>lista;

remove_copy_if(vec.begin(),vec.end(), lista.begin(),Warunek_na_Wysokosc(sredniasu));
 copy(lista.begin(),lista.end(),ostream_iterator<Walec>(cout, " \n"));

And here is Warunek_Na_Wysokosc definition:

struct Warunek_na_Wysokosc
{
    double wys;

   Warunek_na_Wysokosc(const double& h_): wys(h_){ }

    bool operator()(const Walec& w)
    {
        return w.h >= wys;
    }

};

The thing is i get some memory problems if i let it be like that, i mean instructions in main function, and there are none if i set list size. But i want it to be set automatically, should i use some insert function? How to correct this? :) Thanks!

I think you want to use inserter here:

remove_copy_if(vec.begin(),vec.end(),
               std::inserter(lista,lista.end()),
               Warunek_na_Wysokosc(sredniasu));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM