Re: class does not want to get friends with another class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Axel Freyn wrote:
> 
> Hi,
>> 
>> david.hagood wrote:
>> > 
>> > 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&>;
>> > 
>> 
>> No, that does not work. This time, the error is given already before
>> instantiation. The error is that that the third parameter ClassA & is not
>> of
>> the right kind: it is a type instead of a constant instance of that type.
> This is the same problem as in your other mail: You try to make a
> partial template specialization of classB to be friend of classA. That
> won't work (if I understood the C++-Standard correctly in this point...)
> 
> What you can do, is to make friend the "complete" template classA:
> template <class T1, int C1, classA<T1, C1> &instanceA> friend class
> classB;
> 
> works.
> 
> 
> Axel
> 
> 
There is only a partial specialization syntactically, but not semantically.
However, your method works.
-- 
View this message in context: http://old.nabble.com/class-does-not-want-to-get-friends-with-another-class-tp29910278p29916577.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux