operator overld. struct vs. class

  • Thread starter Thread starter Jesper
  • Start date Start date
J

Jesper

Hi,

Are there any serious drawbacks using a class instead of
struct to implementing your own type.

I a textbook of mine on C# the author recommend operator
overloading on value types only. Apparantly based on some
argument that e.g. the ++ operator is more complex to
implement. Can this really be his only reason for this
argument?

Moreover, in a struct, the same aurthor defines the
following

struct Hour
{
.....
.....
private int value;
}

Does he obtain something special using the value keyword
as a field of the struct?

Best regards Jesper
 
Jesper said:
I a textbook of mine on C# the author recommend operator
overloading on value types only. Apparantly based on some
argument that e.g. the ++ operator is more complex to
implement. Can this really be his only reason for this
argument?

Overloading operators may be a bit more detailed with reference types
but I wouldn't say it's more complex. You just have to make sure your
overload has the type of semantics you'd expect from it.
Does he obtain something special using the value keyword
as a field of the struct?

Nope. C# will let you use this keyword as just another variable name.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Back
Top