Template specialization with friend operators and direct implementation

P

Preben

I've encountered a little problem:


when defining these operators

----------

friend bool operator!= <>(const A& p, const V& q) {
return !(p==q);
}

friend bool operator< <>(const A& p, const B& q);

----------


I get an error on the first declaration:
defining explicit specialization 'operator!=<>' in friend declaration

The second declaration works fine


However, when removing the "<>", a warning for the second friend
operator definition appear.

----------

friend bool operator!= (const A& p, const V& q) {
return !(p==q);
}

friend bool operator< (const A& p, const B& q);

----------

and the warning is
friend declaration bool operator< (const A&, const B&) declares a
non-template function


What is the exact difference, and how do I determine the correct use of
"<>" in the second case?



Best regards
Preben
 
P

Preben

when defining these operators
----------

friend bool operator!= <>(const A& p, const V& q) {
return !(p==q);
}

friend bool operator< <>(const A& p, const B& q);

----------

Minor error here: A, V, B should all have been A

----------

friend bool operator!= (const A& p, const V& q) {
return !(p==q);
}

friend bool operator< (const A& p, const B& q);

----------

And the same here

What is the exact difference, and how do I determine the correct use of
"<>" in the second case?


And the implementation of the second operator is given below:
-----------
template<class T>
inline bool operator<(const A& p, const A& q)
{
return (p.member < q.member);
}
-----------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top