Is it possible to make the friend class a template, such as :
template <class T>
class MyClass {
public:
friend class T;
};
The reason why I’m striving to get this is that I’m using policy-based design and I want my policy classes to access the host members.
(…now I begin to think that this might mean my design is simply bad… )
Thanks in advance guys!
In C++03 you are not allowed to declare friendship to an argument of the template.
is ill-formed. ]
In C++11 there has been some changes to this respect, but it is a bit weird.
friend class T;is still illformed, butfriend Tis allowed. A quote can be found in the same paragraph:Notes are not normative, but they indicate the intent of the norms around it. I have not been able to find the specific sentence that makes the note correct, but I assume that at least the intention is that this should be allowed.