Boost logo

Boost Users :

Subject: [Boost-users] [lambda]How can I call function of objects in std::list while using std::for_each?
From: Ç®ÏþÃ÷ (kyleqian_at_[hidden])
Date: 2009-03-22 22:41:39


Please help me! I want to call a virtual function of objects in std::list
while using std::for_each:

struct DiscardableItem {
    void Discard() {
        std::cout<<"Discard item!"<<std::endl;
    }
};
std::list<DiscardableItem*> items;
items.push_back(new DiscardableItem);
items.push_back(new DiscardableItem);
std::for_each( items.rbegin(), items.rend(), _1->*&DiscardableItem::Discard
);

But DiscardableItem::Discard does not be called. How can I make it work?
thanks! I think lambda can solve this problem easily.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net