説明は非常に気が遠くなる可能性があるので、私は例にまっすぐに行きます:
#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>();
}
基本的には、frが呼び出せるようにしたいと思いますfr<int>::privatestuff
。しかし、私も必要以上に公開したくないので、他の人ではなく、他の人とだけfr<int>
友達になりましょう。 fr<bool>::callsomeone<int>
fr<bool>::callsomeone<char>
必要に応じて、c++11を頼りにできます。