There are three types of membership declarations that can appear in the class template:
1. Non-template friends or friends Functions
The Foo () member functions bar () and foobar classes are the friends of all instances of the queueitem class template.
Class Foo {
Void bar ();
};
Template <class T>
Class queueitem {
Friend class foobar;
Friend void Foo ();
Friend void FOO: bar ();
//...
};
2. bound user meta template or function template:
A one-to-one ing is defined between the instance of the queueitem class template and its friends. For each type of queueitem instance, foobar Foo () and queue <t> :: A single related instance of Bar () is youyuan.
Template <class type>
Class foobar {...};
Template <class type>
Void Foo (queueitem <type> );
Template <class type>
Class queue {
Void bar ();
//...
};
Template <class type>
Class queueitem {
Friend class foobar <type>;
Friend void Foo <type> (queueitem <type> );
Friend void queue <type >:: bar ();
//...
};
Friend void Foo <type> (queueitem <type> );
The function name is followed by the explicit template real parameter table Foo <type>. This syntax can be used to specify the instance of the function template Foo () referenced by the membership declaration.
If the explicit template parameters are omitted, the following is shown:
Friend void Foo (queueitem <type> );
The youyuan declaration is interpreted as referencing a non-template function, and the parameter type of this function is an instance of the queueitem class template.
3 unbound user meta template or function template not bound
A one-to-many ing is defined between the instance of the queueitem class template and its friends,
All foobar Foo () and queue <t >:: bar () Instances of each type of queueitem are friends, as shown below:
Template <class type>
Class queueitem {
Template <class T>
Friend class foobar;
Template <class T>
Friend void Foo (queueitem <t> );
Template <class T>
Friend void queue <t >:: bar ();
//...
};
We should note that the compiler before the Standard C ++ does not support this kind of membership statement in the class template.