Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > POD and assignment operator and test operator

Reply
Thread Tools

POD and assignment operator and test operator

 
 
Hicham Mouline
Guest
Posts: n/a
 
      09-01-2009
Hello,

struct S {
double d1;
double d2;
};

S s1,s2;

what was the reason that

s1=s2; // assignment operator (default defined for PODs, right?)

was valid, but not

if (s1 == s2) // test for equality

Regards,


 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      09-01-2009
On Sep 1, 8:10*pm, "Hicham Mouline" <hic...@mouline.org> wrote:
> Hello,
>
> struct S {
> * double d1;
> *double d2;
>
> };
>
> S s1,s2;
>
> what was the reason that
>
> s1=s2; *// assignment operator (default defined for PODs, right?)
>
> was valid, but not
>
> if (s1 == s2) *// test for equality
>
> Regards,


Hi Hicham

Because the first one is copy assignment operator, but the second one
is equality operator.
The first one is declared and defined by compiler implicitly with
default behavior,
but in equality operator case , you have to declare and define its
behavior explicitly.

Regards,
-- Saeed Amrollahi
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      09-01-2009
Hicham Mouline wrote:
> what was the reason that
>
> s1=s2; // assignment operator (default defined for PODs, right?)
>
> was valid, but not
>
> if (s1 == s2) // test for equality


If the compiler was to automatically generate code for the equality
comparison (which would apply the equality comparison to every member),
wouldn't the next question be why the compiler is not doing the same for
operator<() and the other comparison operators?

But in that case, how would the compiler implement those operators?
 
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
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Operator new and POD-struct Ivan A. Kosarev C++ 6 12-02-2005 10:37 AM
Is array of POD still a POD type? Ajax Chelsea C++ 1 12-01-2003 01:56 PM
A (probable) error in perltoot ( perl5/5.8.0/pod/perltoot.pod, line number 756 ) Himanshu Garg Perl Misc 1 09-21-2003 03:28 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57