C# Operator Overloading post-fix increment
Posted
by Victor
on Stack Overflow
See other posts from Stack Overflow
or by Victor
Published on 2009-12-24T11:27:11Z
Indexed on
2010/04/07
1:13 UTC
Read the original article
Hit count: 383
I'm coding a date class and am having trouble with the post-fix increment (the prefix increment seems fine).
Here is the sample code:
public class date
{
int year,
month,
day;
public date(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
static public date operator ++(date d)
{
return d.Next(d);
}
}
The method "Next(date d)" takes a date and returns tomorrows date (I left it out for brevity). I'm to young in C# to understand why the prefix is fine but postfix increment does nothing. But remember in C++ we would have to have two methods instead of just one - for prefix and postfix increments.
Also no errors or warnings on compile.
© Stack Overflow or respective owner