| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Mike - EMAIL IGNORED" |
| Date: |
20 Nov 2003 06:59:32 PM |
| Object: |
template friend problem |
Following 14.5.3, I tried:
class A
{
template<class T> friend class B;
};
where A is a simple non-template class and B is a template.
I tried to use a private method in B from a method in A.
Using gcc-3.2, this fails at compile time, but succeeds
when the method in B is made public.
Is this a compiler bug, or am I missing something?
Thanks for your help.
Mike.
.
|
|
| User: "Victor Bazarov" |
|
| Title: Re: template friend problem |
20 Nov 2003 10:15:54 PM |
|
|
"Mike - EMAIL IGNORED" <m_d_berger_1900@yahoo.com> wrote...
Following 14.5.3, I tried:
class A
{
template<class T> friend class B;
};
where A is a simple non-template class and B is a template.
I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_.
In the situation you showed, 'B' is a friend of 'A', which
means that any member function of 'B' has access to private
members of 'A', not the other way around.
Using gcc-3.2, this fails at compile time, but succeeds
when the method in B is made public.
Is this a compiler bug, or am I missing something?
You're missing something.
Victor
.
|
|
|
| User: "Mike - EMAIL IGNORED" |
|
| Title: Re: template friend problem |
21 Nov 2003 06:15:11 AM |
|
|
Victor Bazarov wrote:
"Mike - EMAIL IGNORED" <m_d_berger_1900@yahoo.com> wrote...
Following 14.5.3, I tried:
class A
{
template<class T> friend class B;
};
where A is a simple non-template class and B is a template.
I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_.
In the situation you showed, 'B' is a friend of 'A', which
means that any member function of 'B' has access to private
members of 'A', not the other way around.
Using gcc-3.2, this fails at compile time, but succeeds
when the method in B is made public.
Is this a compiler bug, or am I missing something?
You're missing something.
Victor
My mistake, I tried to use a method in A from the template B.
Am I still missing something?
Sorry,
Mike.
.
|
|
|
| User: "tom_usenet" |
|
| Title: Re: template friend problem |
21 Nov 2003 08:20:39 AM |
|
|
On Fri, 21 Nov 2003 07:15:11 -0500, Mike - EMAIL IGNORED
<m_d_berger_1900@yahoo.com> wrote:
Victor Bazarov wrote:
"Mike - EMAIL IGNORED" <m_d_berger_1900@yahoo.com> wrote...
Following 14.5.3, I tried:
class A
{
template<class T> friend class B;
};
where A is a simple non-template class and B is a template.
I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_.
In the situation you showed, 'B' is a friend of 'A', which
means that any member function of 'B' has access to private
members of 'A', not the other way around.
Using gcc-3.2, this fails at compile time, but succeeds
when the method in B is made public.
Is this a compiler bug, or am I missing something?
You're missing something.
Victor
My mistake, I tried to use a method in A from the template B.
Am I still missing something?
Yes, this compiles fine in GCC 3.2:
class A
{
template<class T>
friend class B;
int i; //private
};
template <class T>
class B
{
public:
int f()
{
A a;
a.i = 5; //private access
return a.i;
}
};
int main()
{
B<int> b;
b.f();
}
Tom
.
|
|
|
|
|
|

|
Related Articles |
|
|