Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template specialization with friend operators and direct implementation

Reply
Thread Tools

Template specialization with friend operators and direct implementation

 
 
Preben
Guest
Posts: n/a
 
      05-03-2011

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
 
Reply With Quote
 
 
 
 
Preben
Guest
Posts: n/a
 
      05-03-2011
> 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);
}
-----------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with template friend partial specialization Andrey Dj C++ 3 04-05-2012 02:09 PM
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
template specialization in friend function John C++ 2 01-24-2005 01:08 AM
Template friend (unary and binary) operators Ruben Campos C++ 5 11-30-2004 05:07 PM



Advertisments