Topic: friendly nested members of template dummies
Author: Michael Greenspon <mcg@sequin.com>
Date: 1999/10/24 Raw View
Hyman Rosen wrote:
>
> wmm@fastdial.net writes:
> > There are two different questions here, one about T and one about
> > T::m1, and they have different answers.
> >
> > "friend class T;" is explicitly disallowed in 7.1.5.3p2. This was
> > a conscious decision on the part of the Committee, although I'm not
> > aware of the rationale behind that decision.
> >
> > "friend class T::m1;" was, I think, an oversight. There is a pending
> > issue that is related to this question, number 68. I'll make sure
> > that this question is considered when we discuss that issue.
>
> But "T" is a valid name inside class T. So if the second is allowed,
> the first would be, by the stratagem of saying "friend class T::T;".
> Note, by the way, that there is real code which could make good use
> of "friend class T;" if that were permitted.
The last statement certainly is true. We use a lot of 'template API'/generic
patterns where public wrappers are parameterized by implementations (with nested
member classes providing components of the implementation.) There are practical
reasons why the wrappers thus parameterized need to declare the implementations
as friends.
I had assumed this was merely a shortcoming of a particular compiler. I'm rather
surprised (although few things related to computing in general and C++ in
particular surprise me these days) that something this basic is excluded by the
spec and I do not understand the rationale.
Thanks
Michael
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <hymie@prolifics.com>
Date: 1999/10/21 Raw View
wmm@fastdial.net writes:
> There are two different questions here, one about T and one about
> T::m1, and they have different answers.
>
> "friend class T;" is explicitly disallowed in 7.1.5.3p2. This was
> a conscious decision on the part of the Committee, although I'm not
> aware of the rationale behind that decision.
>
> "friend class T::m1;" was, I think, an oversight. There is a pending
> issue that is related to this question, number 68. I'll make sure
> that this question is considered when we discuss that issue.
But "T" is a valid name inside class T. So if the second is allowed,
the first would be, by the stratagem of saying "friend class T::T;".
Note, by the way, that there is real code which could make good use
of "friend class T;" if that were permitted.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <hymie@prolifics.com>
Date: 1999/10/14 Raw View
Michael Greenspon <mcg@sequin.com> writes:
> Consider:
> template< class T >
> class Q {
>
> friend class T;
> friend class T::m1;
>
> };
> What is the correct way to specify this friendliness of nested
> members of a template dummy arg?? What is the role of "typename" in
> this situation?
Unfortunately there is no way to do it. I believe it's because of
an overspecialized syntax for friend declarations. I think the
Standard folks either weren't aware of the problem, or didn't think
it was important enough to fix. Presumably if this *was* legal,
your second friend declaration would require typename in front of
the T::m1.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Michael Greenspon <mcg@sequin.com>
Date: 1999/10/14 Raw View
Consider:
template< class T >
class Q {
friend class T;
friend class T::m1;
};
Where the intent is for Q to be parameterized by a T which must have a member
class m1 and I want to make both of these friends of Q. VC++6.0 (supposedly
more compliant) croaks on this declaration whereas other less compliant
compilers accept it and instantiate it properly. I've tried adding various
permutations of "class T::m1", "typename T::m1" etc to no effect. What is the
correct way to specify this friendliness of nested members of a template dummy
arg?? What is the role of "typename" in this situation?
Thanks,
Michael
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]