I have template <int N> class A;
and template <typename T> class B;
. How do I declare B<A<N>>
to be a friend for all N
? template <int N> friend B<A<N>>;
does not work.
Asked
Active
Viewed 69 times
3

prestokeys
- 4,817
- 3
- 20
- 43
-
https://stackoverflow.com/questions/3292795/how-to-declare-a-templated-struct-class-as-a-friend – Mat Feb 18 '22 at 19:40
-
2@Mat That looks different, as OP only wants a subset of specializations of `B`. – HolyBlackCat Feb 18 '22 at 19:52
-
1A partial specialisation cannot be a friend. – n. m. could be an AI Feb 18 '22 at 20:34
-
Sorry for the intrusion. You said, "How do I declare `B>` to be a friend for all `N`" - a friend to *what* exactly. `A
` ? The who-is-friending-who-and-where failure attempt in full-code would probably be a nice addition to this question, or at least make it clearer to people that don't necessarily sleep with the standard under their pillow. – WhozCraig Feb 18 '22 at 20:56 -
1@WhozCraig a friend to whatever class has a friend declaration I suppose. It doesn't really matter which class it is. You can try `class C { template
friend B>; };` (which doesn't work). – n. m. could be an AI Feb 18 '22 at 22:06 -
@n.1.8e9-where's-my-sharem. yeah, the broken syntax (missing `class/struct`) was what was confusing me. I get it now. And I agree with your first comment. – WhozCraig Feb 18 '22 at 22:31
-
@WhozCraig You can add `class/struct` and it still doesn't work, that's kinda the problem. – n. m. could be an AI Feb 18 '22 at 22:36
-
1Duplicate https://stackoverflow.com/questions/11041274 – cigien Feb 19 '22 at 00:07
-
@n.1.8e9-where's-my-sharem. As I said, I get it now; thus the reason for the "I agree with your first comment" conclusion. – WhozCraig Feb 19 '22 at 02:57