From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: operator != not automatically defined when operator == is defined
Date: Thu, 24 May 2007 18:32:55 +0530 [thread overview]
Message-ID: <46558CFF.1010606@gmail.com> (raw)
Observe:
class MyClass
{
public :
MyClass ( int x ) : i ( x ) {}
bool operator == ( const MyClass & other )
{ return i == other . i ; }
private :
int i ;
} ;
int main ( void )
{
MyClass a ( 1 ), b ( 2 ) ;
if ( a != b ) {}
}
Trying to compile this gives:
operator-notequal.cpp:14: error: no match for ‘operator!=’ in ‘a != b’
Now there need conceivably be no definition for operator != other than
the not-ted value of what operator == gives, so why does gcc want me to
define operator != separately?
Similarly even if I define only operator !=, gcc will tell me to
separately define operator == if I want to use that.
For the pairs:
== and !=
> and <=
< and >=
it is mathematically illogical to have any definition for each operator
in the pair which does not output same as the not-ted output of the
other operator in the pair, but gcc will not allow me to use an operator
unless it has been explicitly defined even if its logical negative
operator has been defined. I believe this is a defect in gcc.
Your comments?
Shriramana Sharma.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2007-05-24 13:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-24 13:02 Shriramana Sharma [this message]
2007-05-25 22:32 ` operator != not automatically defined when operator == is defined Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46558CFF.1010606@gmail.com \
--to=samjnaa@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).