| 1 |
#include <iostream> |
| 2 |
#include <vector> |
| 3 |
|
| 4 |
//HEAD |
| 5 |
template <typename Type> |
| 6 |
class PtrVector: public std::vector<Type *> |
| 7 |
//= |
| 8 |
{ |
| 9 |
public: |
| 10 |
//ITER |
| 11 |
class iterator |
| 12 |
{ |
| 13 |
friend class PtrVector<Type>; |
| 14 |
typename std::vector<Type *>::iterator d_begin; |
| 15 |
|
| 16 |
iterator(PtrVector<Type> &vector); |
| 17 |
|
| 18 |
public: |
| 19 |
Type &operator*(); |
| 20 |
}; |
| 21 |
//= |
| 22 |
iterator begin(); |
| 23 |
}; |
| 24 |
|
| 25 |
//ITERIMP |
| 26 |
template <typename Type> |
| 27 |
PtrVector<Type>::iterator::iterator(PtrVector<Type> &vector) |
| 28 |
: |
| 29 |
d_begin(vector.std::vector<Type *>::begin()) |
| 30 |
{} |
| 31 |
|
| 32 |
template <typename Type> |
| 33 |
Type &PtrVector<Type>::iterator::operator*() |
| 34 |
{ |
| 35 |
return **d_begin; |
| 36 |
} |
| 37 |
//= |
| 38 |
//BEGIN |
| 39 |
template <typename Type> |
| 40 |
typename PtrVector<Type>::iterator PtrVector<Type>::begin() |
| 41 |
{ |
| 42 |
return iterator(*this); |
| 43 |
} |
| 44 |
//= |
| 45 |
|
| 46 |
using namespace std; |
| 47 |
//MAIN |
| 48 |
int main() |
| 49 |
{ |
| 50 |
PtrVector<int> vi; |
| 51 |
|
| 52 |
vi.push_back(new int(1234)); |
| 53 |
|
| 54 |
PtrVector<int>::iterator begin = vi.begin(); |
| 55 |
|
| 56 |
std::cout << *begin << '\n'; |
| 57 |
} |
| 58 |
//= |