While porting an application to Linux I hit a strange compiler error
with GCC 3.3.2. Here is the most stripped down version of the code I
could write:
1 template <typename T> struct SmartPtr
2 {
3 SmartPtr(T*) {}
4 ~SmartPtr() { delete pm_impl; }
5 T* pm_impl;
6 };
7
8 class YYY;
9
10 template <class T>
11 class XXX
12 {
13 friend class SmartPtr< XXX<YYY> >;
14 ~XXX() {}
15 };
16
17 class YYY {};
18
19 int main()
20 {
21 SmartPtr< XXX<YYY> > p(new XXX<YYY>());
22 }
The compiler error is:
: In destructor `SmartPtr<T>::~SmartPtr() [with T = XXX<YYY>]':
:21: instantiated from here
:14: error: `XXX<T>::~XXX() [with T = YYY]' is private
:4: error: within this context
Of course GCC is right that ~XXX() is private, but the friend
declaration is there to take care of that. Other compilers (Comeau,
VC6, VC7) seem to have no problem with this code. Is this a GCC bug?
Can anyone suggest how to make this compile without making ~XXX()
public?
Thanks.