#include <vector>
#include <iostream>
using namespace std;
template<class T>
class myvector:public vector<T>{
public:
T tail;
T head;
void push_back ( const T& x ){
std::vector<T>::push_back(x);
head=this->front();
tail=this->back();
}
void pop_back (){
std::vector<T>::pop_back();
head=this->front();
tail=this->back();
}
};
int main(){
class myvector<int> myv;
int & i=myv.head;
int & j=myv.tail;
myv.push_back(100);
cout<<i<<","<<j<<endl;
myv.push_back(200);
cout<<i<<","<<j<<endl;
myv.push_back(300);
cout<<i<<","<<j<<endl;
myv.pop_back(300);
cout<<i<<","<<j<<endl;
return 0;
}
沒有留言:
張貼留言