user3184866
user3184866

Reputation: 17

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!

Upvotes: 0

Views: 141

Answers (1)

marcinj
marcinj

Reputation: 49986

I think you want to use inserter here:

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

Upvotes: 2

Related Questions