When researching an answer to a question (based on this answer) I tried to do the following:
template <class T>
class friendly {
friend class T;
};
friendly<string> howdy;
This fails to compile with the following error:
error: template parameter “T” may not be used in an
elaborated type specifier
friend class T;
From what I can understand from my good friend Google this is so that I won’t accidentally try to instantiate friendly<int> but why should this be an error when compiling the template? Should’t it be an error when instantiating the template with an invalid type (such as had I written int f() { return T::foo(); })
A bit more googleling brought up Extended
friendDeclarations (PDF) for C++0x.This document contains the following:
Which goes even further than what I thought (ignoring illegal
frienddecelerations rather than failing during instantiation). So I guess the answer is that there isn’t a good reason and it’s being rectified.