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 ------------------
14 const int ArraySize = 12;
17 class Array { // ERROR - .struct Array_RC redecl.*
18 friend class Array_RC;
20 Array(const Type *ar, int sz) { init(ar,sz); }
21 virtual ~Array() { delete [] ia; }
22 virtual void print(ostream& = cout);
23 virtual Type& operator[](int ix) { return ia[ix]; }
25 void init(const Type*, int);
31 ostream& operator<<( ostream& os, Array<Type>& ar )
38 void Array<Type>::print(ostream& os)
40 const int lineLength = 12;
42 os << "( " << size << " )< ";
43 for (int ix = 0; ix < size; ++ix) {
44 if (ix % lineLength == 0 && ix) os << "\n\t";
47 if (ix % lineLength != lineLength-1 &&
55 void Array<Type>::init(const Type *array, int sz)
57 ia = new Type[size = sz];
59 for (int ix = 0; ix < size; ++ix)
60 ia[ix] = (array!=0) ? array[ix] : (Type)0;
63 // --------------- Array_RC.h && Array_RC.cc ----------------
66 class Array_RC : public Array<Type> {// ERROR - previous declaration.*
68 Array_RC(const Type *ar, int sz);
69 Type& operator[](int ix);
73 Array_RC<Type>::Array_RC(const Type *ar, int sz) : Array<Type>(ar, sz) {}
76 Type &Array_RC<Type>::operator[](int ix) {
77 assert(ix >= 0 && ix < size);// ERROR - member .size.*
78 return ia[ix];// ERROR - member .ia.*
81 // ------------------- Test routine ----------------------
84 void try_array( Array<Type> &iA )
86 cout << "try_array: initial array values:\n";
92 try_array( Array_RC<Type> &rc )
94 try_array( ((Array<Type>&)rc) );
99 static int ia[10] = { 12, 7, 14, 9, 128, 17, 6, 3, 27, 5 };
100 Array_RC<int> iA(ia, 10);// ERROR - instantiated from here
102 cout << "template Array_RC class" << endl;
108 template class Array_RC<int>;