OSDN Git Service

fix implicit int
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.law / visibility13.C
1 // Build don't link: 
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.h>
10 #include <assert.h>
11
12 //     ---------------   Array.h  &&  Array.cc   ------------------
13
14 const int ArraySize = 12;
15
16 template <class Type>
17 class Array { // ERROR - .struct Array_RC redecl.*
18 friend class Array_RC;
19 public:
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]; }
24 private:
25     void init(const Type*, int);
26     int size;
27     int *ia;
28 };
29
30 template <class Type>
31 ostream& operator<<( ostream& os, Array<Type>& ar )
32 {
33     ar.print(os);
34     return os;
35 }
36
37 template <class Type>
38 void Array<Type>::print(ostream& os)
39 {
40     const int lineLength = 12;
41
42     os << "( " << size << " )< ";
43     for (int ix = 0; ix < size; ++ix) {
44         if (ix % lineLength == 0 && ix) os << "\n\t";
45         os << ia[ ix ];
46
47         if (ix % lineLength != lineLength-1 &&
48             ix != size-1)
49             os << ", ";
50     }
51     os << " >\n";
52 }
53
54 template <class Type>
55 void Array<Type>::init(const Type *array, int sz)
56 {
57     ia = new Type[size = sz];
58
59     for (int ix = 0; ix < size; ++ix)
60         ia[ix] = (array!=0) ? array[ix] : (Type)0;
61 }
62
63 //     ---------------   Array_RC.h  &&  Array_RC.cc   ----------------
64
65 template <class Type>
66 class Array_RC : public Array<Type> {// ERROR - previous declaration.*
67 public:
68     Array_RC(const Type *ar, int sz);
69     Type& operator[](int ix);
70 };
71
72 template <class Type>
73 Array_RC<Type>::Array_RC(const Type *ar, int sz) : Array<Type>(ar, sz) {}
74
75 template <class Type>
76 Type &Array_RC<Type>::operator[](int ix) {
77     assert(ix >= 0 && ix < size);// ERROR - member .size.*
78     return ia[ix];// ERROR - member .ia.*
79 }
80
81 //    -------------------   Test routine   ----------------------
82
83 template <class Type>
84 void try_array( Array<Type> &iA )
85 {
86     cout << "try_array: initial array values:\n";
87     cout << iA << endl;
88 }
89
90 template <class Type>
91 inline void
92 try_array( Array_RC<Type> &rc )
93 {
94     try_array( ((Array<Type>&)rc) );
95 }
96
97 int main()
98 {
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
101
102     cout << "template Array_RC class" << endl;
103     try_array(iA);
104
105     return 0;
106 }
107
108 template class Array_RC<int>;