I want to support a global binary operator on the inner class of a template class:
template <unsigned N, typename T>
class Parent
{
public:
class Child
{
public:
Child & operator |= (const Child &);
};
};
template <unsigned N, typename T>
typename Parent<N,T>::Child
operator | (
const typename Parent<N,T>::Child & a,
const typename Parent<N,T>::Child & b)
{
return Parent<N,T>::Child (a) |= b;
}
int main ()
{
Parent<1,char>::Child a;
Parent<1,char>::Child b;
auto c = a | b;
}
To my eyes, the expression a|b
should have no trouble agreeing with the operator|
prototype, but (gcc 7.3.0):
error: no match for ‘operator|’ (operand types are ‘Parent<1, char>::Child’ and ‘Parent<1, char>::Child’)
...
template argument deduction/substitution failed:
couldn't deduce template parameter ‘N’
Note that this works:
auto c = Parent<1,char>::Child(a) |= b
Why doesn't the global operator work?