This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: class does not want to get friends with another class
- From: David Hagood <david dot hagood at gmail dot com>
- To: brac37 <MichieldeB at aim dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 07 Oct 2010 20:21:04 -0500
- Subject: Re: class does not want to get friends with another class
- References: <29910278.post@talk.nabble.com>
On Thu, 2010-10-07 at 14:08 -0700, brac37 wrote:
> Hello,
>
> I have some code that works when I make class classA public. But I only want
> class classA to be accessible by itself and class classB. So the problem is
> very concrete: make classB a friend of classA.
>
> Here is the code that describes both classes.
>
>
>
> template <class T, int C> class classA;
>
> template <class T, int C, classA<T,C> &instanceA> class classB;
>
> template <class T, int C> class classA
> {
>
> template <classA &instanceA> friend class classB;
I think your problem is that you are not fully specifying the template
parameters for class B, thus as far as class A is concerned, you are
speaking of some other class B.
I think you have to fully spec out class B here:
friend class classB<T,C,classA&>;
>
>
> private:
> int for_use_by_classB;
>
> };
>
> template <class T, int C, classA<T,C> &instanceA> class classB
> {
>
> classB (int i) { instanceA.for_use_by_classB = i; }
>
> };
>
> // instantiation gives error
> // template class classA<char,128>;
>