vector-push_back

////////////////////////////////////////
//      2018/04/17 20:54:41
//      vector-push_back
#include <iostream>
#include <vector>
#include <string>
#include <iterator>

using namespace std;

template<class T>
class Name
{
private:
    T name;
public:
    Name(T t) :name(t){};
    void print(){
        cout << name << " ";
    }
};

//========================

int main()
{
    typedef Name<string> N;
    typedef vector<N> V;
    V v;
    N n1("Robert");
    N n2("Alex");
    v.push_back(n1);
    v.push_back(n2);

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

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