deque-push_back

////////////////////////////////////////
//      2018/04/24 20:02:33
//      deque-push_back

#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_back(n1);
    d.push_back(n2);

    //unname object of the type Name
    d.push_back(N("Linda"));
    D::iterator it = d.begin();
    while (it != d.end()){
        (it++)->print();
    }

    cout << endl;
    return 0;
}

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