| 1 |
// { dg-do compile } |
| 2 |
|
| 3 |
// Copyright (C) 2004 Free Software Foundation |
| 4 |
// Contributed by Kriang Lerdsuwanakij <[email protected]> |
| 5 |
|
| 6 |
// Nested class of class template as friend |
| 7 |
|
| 8 |
template<class T> struct A |
| 9 |
{ |
| 10 |
struct B |
| 11 |
{ |
| 12 |
void f(); |
| 13 |
}; |
| 14 |
}; |
| 15 |
|
| 16 |
class C { |
| 17 |
int i; |
| 18 |
template<class T> friend struct A<T>::B; |
| 19 |
}; |
| 20 |
|
| 21 |
template<class T> struct A<T*> |
| 22 |
{ |
| 23 |
struct B |
| 24 |
{ |
| 25 |
void f(); |
| 26 |
}; |
| 27 |
}; |
| 28 |
|
| 29 |
template<> struct A<char> |
| 30 |
{ |
| 31 |
struct B |
| 32 |
{ |
| 33 |
void f(); |
| 34 |
}; |
| 35 |
}; |
| 36 |
|
| 37 |
template<class T> void A<T>::B::f() |
| 38 |
{ |
| 39 |
C c; |
| 40 |
c.i = 0; |
| 41 |
} |
| 42 |
|
| 43 |
template<class T> void A<T*>::B::f() |
| 44 |
{ |
| 45 |
C c; |
| 46 |
c.i = 0; |
| 47 |
} |
| 48 |
|
| 49 |
void A<char>::B::f() |
| 50 |
{ |
| 51 |
C c; |
| 52 |
c.i = 0; |
| 53 |
} |
| 54 |
|
| 55 |
int main() |
| 56 |
{ |
| 57 |
A<int>::B b1; |
| 58 |
b1.f(); |
| 59 |
A<int *>::B b2; |
| 60 |
b2.f(); |
| 61 |
A<char>::B b3; |
| 62 |
b3.f(); |
| 63 |
} |