This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Templated friends?


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]