In this scenario, you're defining a binary tree class template (BT) and a class template (BE) that represents an element of the tree. You encounter a peculiar requirement to declare the friend template as BT instead of BT
Initially, you attempt to declare the friend template as template
When you declare template
If you wish to restrict the friend relationship to only those instantiations of BT that utilize the same template argument as BE, you should declare the friend as follows:
template<class T> friend class bar<T>;
In your specific case, declaring friend class bar
The above is the detailed content of Why Does a Templated Class Need to Declare a Friend Templated Class with a Different Template Parameter?. For more information, please follow other related articles on the PHP Chinese website!