1// { dg-do assemble  }
2// GROUPS passed visibility
3// visibility file
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>
8
9#include <iostream>
10#include <cassert>
11
12//     ---------------   Array.h  &&  Array.cc   ------------------
13
14using namespace std;
15
16const int ArraySize = 12;
17
18template <class Type>
19class Array { // { dg-error "" } .struct Array_RC redecl.*
20friend class Array_RC;
21public:
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]; }
26private:
27    void init(const Type*, int);
28    int size;
29    int *ia;
30};
31
32template <class Type>
33ostream& operator<<( ostream& os, Array<Type>& ar )
34{
35    ar.print(os);
36    return os;
37}
38
39template <class Type>
40void Array<Type>::print(ostream& os)
41{
42    const int lineLength = 12;
43
44    os << "( " << size << " )< ";
45    for (int ix = 0; ix < size; ++ix) {
46        if (ix % lineLength == 0 && ix) os << "\n\t";
47        os << ia[ ix ];
48
49        if (ix % lineLength != lineLength-1 &&
50            ix != size-1)
51            os << ", ";
52    }
53    os << " >\n";
54}
55
56template <class Type>
57void Array<Type>::init(const Type *array, int sz)
58{
59    ia = new Type[size = sz];
60
61    for (int ix = 0; ix < size; ++ix)
62        ia[ix] = (array!=0) ? array[ix] : (Type)0;
63}
64
65//     ---------------   Array_RC.h  &&  Array_RC.cc   ----------------
66
67template <class Type>
68class Array_RC : public Array<Type> {
69public:
70    Array_RC(const Type *ar, int sz);
71    Type& operator[](int ix);
72};
73
74template <class Type>
75Array_RC<Type>::Array_RC(const Type *ar, int sz) : Array<Type>(ar, sz) {}
76
77template <class Type>
78Type &Array_RC<Type>::operator[](int ix) {
79    assert(ix >= 0 && ix < size);// { dg-error "" } member .size.*
80    return ia[ix];// { dg-error "" } member .ia.*
81}
82
83//    -------------------   Test routine   ----------------------
84
85template <class Type>
86void try_array( Array<Type> &iA )
87{
88    cout << "try_array: initial array values:\n";
89    cout << iA << endl;
90}
91
92template <class Type>
93inline void
94try_array( Array_RC<Type> &rc )
95{
96    try_array( ((Array<Type>&)rc) );
97}
98
99int main()
100{
101    static int ia[10] = { 12, 7, 14, 9, 128, 17, 6, 3, 27, 5 };
102    Array_RC<int> iA(ia, 10);
103
104    cout << "template Array_RC class" << endl;
105    try_array(iA);
106
107    return 0;
108}
109
110template class Array_RC<int>;
111