In C++03 the following is illegal, although some compilers support it.
template <class T>
class X
{
friend T;
};
Has this been legalized in C++11? (Sorry, didn't have time to read the draft myself, just hoping someone knows this)
One-to-one: A template function instantiated with one set of template arguments may be a friend to one template class instantiated with the same set of template arguments. This is also the relationship between a regular non-template class and a regular non-template friend function.
In UML models, template parameters are formal parameters that once bound to actual values, called template arguments, make templates usable model elements. You can use template parameters to create general definitions of particular types of template.
Similar to how standard function parameters may be used to send values to a function, template parameters allow you to pass types to a function as well. A template parameter is a specific form of the parameter that can be used to pass a type as an argument.
A template non-type parameter is a template parameter where the type of the parameter is predefined and is substituted for a constexpr value passed in as an argument. A non-type parameter can be any of the following types: An integral type. An enumeration type.
From section §11.3, 3 in N3291:
template <typename T> class R {
friend T;
};
R<C> rc; // class C is a friend of R<C>
R<int> Ri; // OK: "friend int;" is ignored
So it is legal in C++11.
Yes c++0x allows template parameter to be friends.
Well, I happened to remember read it in the draft before but could not find the reference..anyways @Praetorian's answer nailed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With