C# Operator Overloading post-fix increment
- by Victor
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.