| 1 |
// { dg-do assemble } |
| 2 |
// GROUPS passed templates |
| 3 |
template<class T> |
| 4 |
class Vector |
| 5 |
{ |
| 6 |
public: |
| 7 |
Vector(int x); |
| 8 |
~Vector(); |
| 9 |
T& operator [] (int i); |
| 10 |
|
| 11 |
private: |
| 12 |
T* v; |
| 13 |
int sz; |
| 14 |
} ; |
| 15 |
|
| 16 |
template<class T> |
| 17 |
Vector<T>::Vector(int x) |
| 18 |
{ |
| 19 |
sz = x; |
| 20 |
v = new T (sz); |
| 21 |
} |
| 22 |
|
| 23 |
template<class T> |
| 24 |
Vector<T>::~Vector() |
| 25 |
{ delete [] v; } |
| 26 |
|
| 27 |
template<class T> |
| 28 |
T & |
| 29 |
Vector<T>::operator [] (int i) |
| 30 |
{ return v[i]; } |
| 31 |
|
| 32 |
int |
| 33 |
main(int, char **) |
| 34 |
{ |
| 35 |
Vector<int> intvec(3); |
| 36 |
|
| 37 |
intvec[0] = 1; |
| 38 |
intvec[1] = 2; |
| 39 |
intvec[2] = 3; |
| 40 |
|
| 41 |
for (int i = 0; i < 3; i++) |
| 42 |
intvec[i]; |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|