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

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

 



Hi,
On Fri, Oct 08, 2010 at 06:24:13AM -0700, brac37 wrote:
> Another friend declaration gives an error message which is incorrect.
In fact, I belive the error is correct!
> template <class T, int C> class classA;
> template <class T, int C, classA<T,C> &instanceA> class classB;
Here you define the template "classB": it takes 3 template parameters: 
 - one data-type, "T"
 - one integer, "C"
 - a variable of type "classA<T,C>&", "instanceA"
> template <class T, int C> class classA
> {
>   // error message on instantiation: too few template parameters (1 < 3)
>   template <classA &instanceA> friend class classB;
Here you use class B as if it would have only one template parameter --
that can't work
>   
>   // incorrect error message: partial specialization claimed but not apparent 
>   // template <classA &instanceA> friend class classB<T,C,instanceA>;
Partial template specializations as friends are forbidden by C++:
§14.5.3.8 states: "Friend declarations shall not declare partial
spezializations". And you are trying here to do a partial
specialization...
What you can do instead:
    template <class T1, int C1, classA<T1,C1> &instanceA> friend class classB;
will compile and declare "classB" to be friend of classA (then, also
"classB<char, 127,A1>" will be a friend of classA<char, 128>).

HTH,

Axel


[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