* Templated friends?
@ 2003-01-14 16:26 Richard Guenther
0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2003-01-14 16:26 UTC (permalink / raw)
To: gcc
Hi!
Are we supposed to accept something like
template <class X>
class A {
void bar() const;
template <class Y>
void foo(const A<Y>& a) const {
a.bar();
}
template <class Y>
friend class A;
};
int main(int argc, char **argv)
{
A<int> a;
A<double> b;
a.foo(b);
return 0;
}
The above gives
templatedfirends.cpp:5: error: `void A<X>::foo(const A<Y>&) const [with Y
= double, X = int]' is private
templatedfirends.cpp:16: error: within this context
which is incorrect(?)
Thanks, Richard.
--
Richard Guenther <richard.guenther@uni-tuebingen.de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Templated friends?
@ 2003-01-14 17:52 Volker Reichelt
0 siblings, 0 replies; 2+ messages in thread
From: Volker Reichelt @ 2003-01-14 17:52 UTC (permalink / raw)
To: rguenth; +Cc: gcc
Hi,
> template <class X>
> class A {
> void bar() const;
> template <class Y>
> void foo(const A<Y>& a) const {
> a.bar();
> }
> template <class Y>
> friend class A;
> };
>
> int main(int argc, char **argv)
> {
> A<int> a;
> A<double> b;
> a.foo(b);
> return 0;
> }
Your code is ill-formed. "foo" is a private member of "A" and therefore
can be called only inside member functions or friends. But "main" does not
belong to this category. You have to declare "foo" as a public member
to make the code compile.
Regards,
Volker
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-01-14 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-14 16:26 Templated friends? Richard Guenther
2003-01-14 17:52 Volker Reichelt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).