In the realm of C , declaring templated structs or classes as friends can present a syntax-related roadblock. To achieve this, consider the following approach:
templatestruct foo { template friend class foo; private: // ... };
This syntax appears to compile successfully. However, it declares all template instantiations of foo as friends to each other, regardless of the template parameter they take. This may or may not align with your intended use case.
If you need to limit the friendship to only specific instantiations, you can achieve this using this syntax:
templatestruct foo { template friend struct foo ; private: // ... };
Unfortunately, this syntax doesn't allow for a generic declaration that includes all possible instantiations of foo.
Therefore, if your goal is to establish friendship across all of foo's template instantiations, the second approach using friend class foo is the closest you can get, given the constraints of C syntax.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3