deque-push_front

////////////////////////////////////////
//      2018/04/24 20:09:27
//      deque-push_front

#include <iostream>
#include <deque>
#include <string>
#include <iterator>

using namespace std;
template<class T>
class Name{
private:
    T name;
public:
    void print(){
        cout << name << " ";
    }
    Name(T t) :name(t){}
};
//=========================
int main(){
    typedef Name<string> N;
    typedef deque<N> D;
    D d;
    N n1("Robert");
    N n2("Alex");
    d.push_front(n1);
    d.push_front(n2);

    // unnmaed object of the type Name
    d.push_front(N("Linda"));
    D::iterator it = d.begin();
    while (it != d.end()){
        (it++)->print();
    }
    cout << endl;
    return 0;
}


/*
OUTPUT:
  Linda Alex Robert
*/ 
posted @ 2018-04-24 20:24  老耗子  阅读(59)  评论(0编辑  收藏  举报