"Tom Widmer [VC++ MVP]" <tom_usenet@hotmail.com> wrote in message
news:uKAKjKkDHHA.3676@TK2MSFTNGP03.phx.gbl...
Mycroft Holmes wrote:
Hi,
Two questions on friendship:
1) Is it possible to make any "inner" friend of any other "inner", let's
say for a fixed X?
as in this pseudo-code:
template <typename X>
class outer
{
template <typename Y>
class inner
{
// pseudo-C++
template <typename ANY>
friend class inner;
};
};
I think that code is probably legal - I can't see anything forbidding it
in the standard. However, neither VC8 nor Comeau C++ like it. GCC does
though.
It looks like we are using the same compilers :)
I think from the error messages that VC8 and Comeau do look for a complete
signature of "inner" (e.g. something like friend class outer<X>::inner).
Comeau in particular does not understand that "inner" is the same as
"outer<X>::inner".
GCC takes the code with meaning "outer<X>::inner<Y> is a friend of
outer<X>::inner<Z>", fixed X, for any Y and Z.
But the compiler cannot possibly know that outer<X>::inner is a template for
any X... so I won't bet GCC is completely right.
template <typename Y>
class someclass
{
friend class someclass<const Y>;
};
even if Y is already const.
Yes, I think it's legal. However, you may find it simpler to partially
specialize for const instead.
well, my situation is much simpler: class C<T> holds a private T*, and I'd
like to construct C<const T> from a C<T>, so friendship - if legal - should
suffice.