c++ - Force instantiation of friend functions -
assume have template class friend function:
template<class t> class { friend operator+ (int, const a&); };
this function implemented somewhere below:
template<class t> a<t> operator+ (int i, const a<t>& a) { ... }
and there force instantiation of class template further below:
template class a<int>;
does imply operator+(int, a<int>)
compiled? or have force instantiate separately achieve that?
template parameters aren't automatically forwarded friend
declarations. need specify template parameter function well:
template<class t> class { template<class u> friend a<u> operator+ (int, const a<u>&); };
implementation correct, should be
template<class t> a<t> operator+ (int i, const a<t>& a) { // ^^^ // ... }
Comments
Post a Comment