template friend for operator- How to
Hi,
I have a problem with a friend declaration of the dyadic operator- IFF there is a monadic operator-, as well.
Note that the friend declaration below is accepted if and only if the definition of the monadic operator
is removed.
Many thanks for a hint,
Helmut
template <typename INT,INT P> class Zp;
template <typename INT,INT P>
Zp<INT,P> operator-(const Zp<INT,P>& a, const Zp<INT,P>& b);
template <typename INT,INT P>
class Zp {
public:
static const INT p = P;
private:
INT val;
public:
Zp() : val(0) {}
Zp( INT x ) : val(x%p) { if (x < 0 ) x+= p; }
Zp operator-() const { return Zp(p-val); } // if this is deleted, it works <<<<<
friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b);
/* gcc-4.9.0 says
Quest_Templ.C:22:28: error: declaration of 'operator-' as non-function
friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b);
^
Quest_Templ.C:22:28: error: expected ';' at end of member declaration
Quest_Templ.C:22:30: error: expected unqualified-id before '<' token
friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b);
*/
};