C++ 模板类中模板方法的朋友,在模板类中

C++ 模板类中模板方法的朋友,在模板类中,c++,templates,c++11,friend,C++,Templates,C++11,Friend,描述可能令人难以置信,因此我直接进入示例: #include <iostream> #include <typeinfo> using namespace std; template<typename T> class fr{ static void privatestuff(){ cout<<"private of "<<typeid(T).name()<<endl; } public:

描述可能令人难以置信,因此我直接进入示例:

#include <iostream>
#include <typeinfo>
using namespace std;

template<typename T> class fr{
    static void privatestuff(){
        cout<<"private of "<<typeid(T).name()<<endl;
    }
public:
    template<typename TT> void callsomeone(){
        fr<TT>::privatestuff();
    }
    //template<typename TT> friend void fr<TT>::callsomeone<T>();
    //template<> template<typename TT> friend void fr<TT>::callsomeone<T>();
    //template<typename TT> template<> friend void fr<TT>::callsomeone<T>();
    //no other combinations... how to get it?
};

int main(){
    fr<bool> obj;
    obj.callsomeone<int>();
}
#包括
#包括
使用名称空间std;
模板类fr{
静态void privatestuff(){
cout
template-template-friend-void-fr::callsomeone();

您不应将任何模板参数传递给callsomeone,因为您希望成为函数模板的朋友,而不是它的专门化(换句话说,您希望成为它的所有专门化的朋友)。

问题在于代码中的注释。这意味着什么?不知道……您想要
callsomeone()
要成为
fr的朋友
?如果我理解你是正确的-你需要将callsomeone()声明为类fr的朋友函数才能调用私有fr的函数。正确吗?但是
callsomeone()
是一个成员函数模板,它一开始不需要是朋友。或者我遗漏了什么吗?他希望fr::callsomeone成为fr的一员。那应该是fd吗?y在哪里?这不意味着向任何TT声明友好吗?我只想在TT=Tno时让它成为朋友,他的类模板称为fr,而不是fd。我没有Idea他为什么在朋友声明中使用fd。我相信我现在明白了。你的意图。我将在规范中查找与单个函数模板成为朋友的条件,稍后对类模板进行序列化,但我似乎记得这是不可能的。顺便问一下,你能将这些规范链接到我吗?
template<class x> template<class y> friend void fr<x>::callsomeone();