加文

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

list back

#include <iostream>
#include <list>
#include <algorithm>
#include <string>
#include <iterator>
using namespace std;
template<class T, class D>
class Member
{
    public:
        Member(T t, D d) : name(t), sal(d) {}
        void print();
    private:
        T name;
        D sal;
};
template<class T, class D>
void Member<T,D>::print()
{
    cout << name << "  " << sal << endl;
}
//--------------------------------------
int main ()
{
    typedef Member<string,double> M;
    list<M> l;

    l.push_back(M("Robert",60000));
    l.push_back(M("Linda",75000));

    list<M>::iterator It = l.begin();
    cout << "Entire list:" << endl;

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

    cout << "Return from back()" << endl;
    l.back().print();
    getchar();
    return 0;
}

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


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