2 // GROUPS passed visibility
4 // From: dinh@cs.ucla.edu (Dinh Le)
5 // Date: Mon, 12 Jul 93 22:21:06 -0700
6 // Subject: class, template and their scoping problem
7 // Message-ID: <9307130521.AA18312@oahu.cs.ucla.edu>
12 // --------------- Array.h && Array.cc ------------------
16 const int ArraySize = 12;
19 class Array { // { dg-error "" } .struct Array_RC redecl.*
20 friend class Array_RC;
22 Array(const Type *ar, int sz) { init(ar,sz); }
23 virtual ~Array() { delete [] ia; }
24 virtual void print(ostream& = cout);
25 virtual Type& operator[](int ix) { return ia[ix]; }
27 void init(const Type*, int);
33 ostream& operator<<( ostream& os, Array<Type>& ar )
40 void Array<Type>::print(ostream& os)
42 const int lineLength = 12;
44 os << "( " << size << " )< ";
45 for (int ix = 0; ix < size; ++ix) {
46 if (ix % lineLength == 0 && ix) os << "\n\t";
49 if (ix % lineLength != lineLength-1 &&
57 void Array<Type>::init(const Type *array, int sz)
59 ia = new Type[size = sz];
61 for (int ix = 0; ix < size; ++ix)
62 ia[ix] = (array!=0) ? array[ix] : (Type)0;
65 // --------------- Array_RC.h && Array_RC.cc ----------------
68 class Array_RC : public Array<Type> {
70 Array_RC(const Type *ar, int sz);
71 Type& operator[](int ix);
75 Array_RC<Type>::Array_RC(const Type *ar, int sz) : Array<Type>(ar, sz) {}
78 Type &Array_RC<Type>::operator[](int ix) {
79 assert(ix >= 0 && ix < size);// { dg-error "" } member .size.*
80 return ia[ix];// { dg-error "" } member .ia.*
83 // ------------------- Test routine ----------------------
86 void try_array( Array<Type> &iA )
88 cout << "try_array: initial array values:\n";
94 try_array( Array_RC<Type> &rc )
96 try_array( ((Array<Type>&)rc) );
101 static int ia[10] = { 12, 7, 14, 9, 128, 17, 6, 3, 27, 5 };
102 Array_RC<int> iA(ia, 10);
104 cout << "template Array_RC class" << endl;
110 template class Array_RC<int>;