加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

list remove

#include <iostream>
#include <list>
#include <algorithm>
#include <string>
using namespace std;

template <class T, class D>
class Salary
{
    public:
        Salary(T t) : id(t) {}
        Salary(T t,D d) : id(t), sal(d) {}
        void print ()
        { cout << id << "  " << sal << endl; }
    private:
        T id;
        D sal;
    friend bool operator == 
        (const Salary& s1,const Salary& s2)
    { return s1.id == s2.id; }
};
//==========================================
int main () 
{
    typedef Salary<string,double> S;
    typedef list<S> L;

    L l;
    l.push_back(S("012345",70000.0));
    l.push_back(S("012346",60000.0));
    l.push_back(S("012347",72000.0));

    L::iterator It = l.begin();
    while ( It != l.end() )
        (It++)->print();
    cout << endl;

    S s("012345");
    l.remove(s);
        
    It = l.begin();
    while ( It != l.end() )
        (It++)->print();
    cout << endl;
    getchar();
    return 0;
}

posted on 2012-04-12 11:50 加文 阅读(350) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理