Re: May a template argument be a friends of the template class?

From: Malte Starostik (malte_at_starostik.de)
Date: 03/29/05


Date: Tue, 29 Mar 2005 04:28:23 +0200

Victor Bazarov schrieb:
> I don't know about g++ 3.4.2 but Comeau C++ (online trial) refuses to
> compile
>
> template<class T> class A {
> friend class T;
> int a;
> };
>
> explaining that 'T' "may not be used in an elaborate type specifier",
> although I can't find anything against it in the Standard. [Aside:
> it would really be nice if compilers in the cases where they give
> diagnostic messages re ill-formed code, supplied at least the clause
> of the Standard related to the issue, better if it were the paragraph]

Full Ack.

> It would be nice if somebody more versed in the Standard explained...

11.4 Friends, paragraph 2 requires an elaborated-type-specifier for a
friend declaration of a class.

7.1.5.3 Elaborated type specifiers, paragraph 2 explicitly refers to it:
[...] If the identifier resolves to a typedef-name or a template
type-parameter, the elaborated-type-specifier is ill-formed [Note: this
implies that, within a class template with a template type-parameter T,
the declaration
friend class T;
is ill-formed]

Not that I have any idea about the rationale for this...

Cheers,
Malte



Relevant Pages

  • Re: Template friend (unary and binary) operators
    ... that with unary operator- as a friend function. ... template class MyTemplate; ... Trying to compile this wit MS Visual C++ 7.x returns me some syntax and ...
    (comp.lang.cpp)
  • template -> instance -> function unresolved ???
    ... friend template function accessing private data in the template. ... i compile this into a dll (yes i know, there is no exported function from ...
    (microsoft.public.vc.language)
  • Re: template -> instance -> function unresolved ???
    ... friend template function accessing private data in the template. ... i compile this into a dll (yes i know, there is no exported function from ... template <class Element> ...
    (microsoft.public.vc.language)
  • Re: Why wont this compile
    ... Can someone explain why the following code won't compile in both VC7 and VC8 ... You haven't made the function a friend. ... friend void Func; ... template void Func; is a friend, not the function template void Func; which is presumably closer to what is desired. ...
    (microsoft.public.vc.language)
  • Re: [!! RANT !!] This is a hack at best (C4251)
    ... Micro$oft support for STL and standards in general is absolutely appaling. ... The built DLL exports the symbols, so I am not sure why the compiler issues the warnings. ... The function template is completely ignored and not even exported. ... I hope you can provide a fix as to how to get this to work (i.e. compile ...
    (microsoft.public.dotnet.languages.vc)