Friend class within templates

Stuart Brooks
Mon Jul 19 08:20:00 GMT 2004

We are busy recompiling code under g++ 3.3.3 (Netbsd 2.0) and have come up
with a couple of problems. The previous compiler was g++ 2.95.3.

One in particular concerns the use of friend classes from within templates
viz the example below.

template<class T> OwnerClass

  friend class T;
  void tellUsSomething() {} // called from T

The 3.3.3 compiler gives "error: using template type parameter 'T' after
'class'" which it didn't give under 2.95.3. I have had a look through
Stroustrup's "The C++ Programming Language" and couldn't find a direct
reference to this case, but presume it contravenes the C++ standard in some

I was wondering if this is the case, and if so whether somebody has a clever
way to work around this easily. I have attached a short test program as an

-------------- next part --------------
A non-text attachment was scrubbed...
Name: testprog.tgz
Type: application/octet-stream
Size: 455 bytes
Desc: not available
URL: <>

More information about the Gcc-help mailing list