class does not want to get friends with another class
Axel Freyn
axel-freyn@gmx.de
Fri Oct 8 15:41:00 GMT 2010
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
More information about the Gcc-help
mailing list