0

The description can be quite mind boggling so I get straight to the example:

#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>();
}

Basically, I want fr to be able to call fr<int>::privatestuff. But I'd like also to not expose more than what is needed, so make fr<int> friend of only fr<bool>::callsomeone<int>, not fr<bool>::callsomeone<char> or others.

I can count on c++11 if that's needed.

Lorenzo Pistone
  • 5,028
  • 3
  • 34
  • 65

1 Answers1

1
template<class x> template<class y> friend void fr<x>::callsomeone();

You shall not pass any template arguments to callsomeone, because you want to befriend a function template, and not a specialization of it (in other words, you want to befriend all specializations of it).

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212