Hey guys I have this problem where I'm trying to use the "++" operator with objects. I'm new to classes and I don't know exactly where I can find the problem so I'm posting my whole code...
Code:
#include<iomanip.h>
class Date
{
private:
int month;
int day;
int year;
public:
Date(int=1,int=1,int=2001);
Date(long);
Date(const Date&);
Date operator++(int);
void setdate(int, int, int);
void showdate();
};
Date::Date(int mm, int dd, int yyyy)
{
month=mm;
day=dd;
year=yyyy;
}
Date::Date(long yyyymmdd)
{
year=int(yyyymmdd/10000);
month=int((yyyymmdd-year*10000)/100);
day=int(yyyymmdd-year*10000-month*100);
}
Date::Date(const Date& olddate)
{
month=olddate.month;
day=olddate.day;
year=olddate.year;
}
Date Date::operator++(int day)
{
day=day+1;
}
void Date::setdate(int mm, int dd, int yyyy)
{
month =mm;
day=dd;
year=yyyy;
return;
}
void Date::showdate()
{
cout<<setfill('0');
cout<<setw(2)<<month<<'/'
<<setw(2)<<day<<'/'
<<setw(2)<<year<<" ";
}
main()
{ int i;
Date d1,d2(03,21,2002);
Date d3(d1);
Date d4=d2;
Date d5(20020507L);
cout<<"Date 1="; d1.showdate(); cout<<"Date 2=";d2.showdate();
cout<<"Date 3="; d3.showdate(); cout<<"Date 4=";d4.showdate();
cout<<"Date 5="; d5.showdate(); cout<<endl;
++d1;/* d2=d2+30; d3++; i=d2-d4; d5=d1;
cout<<"Date 1="<<d1.showdate(); cout<<"Date 2="<<d2.showdate();
cout<<"Date 3="<<d3.showdate(); cout<<"Date 4="<<d4.showdate();
cout<<"Date 5="<<d5.showdate(); cout<<endl;
cout<<"i="<<i<<endl;
d1--; --d3; d5=20020507L;
if(d1==d3)
cout<<"Date 1 and Date 3 are equal\n";
else
cout<<"Date 1 and Date 3 are not equal\n";
if(d2>d4)
cout<<"Date 2 is greater than Date 4\n";
else
cout<<"Date 2 is not greater than Date 4\n";
cout<<"Date 1="<<d1.showdate(); cout<<"Date 2="<<d2.showdate();
cout<<"Date 3="<<d3.showdate(); cout<<"Date 4="<<d4.showdate();
cout<<"Date 5="<<d5.showdate(); cout<<endl;
*/
return 0;
}
The compiler gives me these errors:
You will find them in Red
lb05fa02.C: In function `int main()':
lb05fa02.C:91: no match for `++Date &'
lb05fa02.C:53: candidates are: class Date Date:perator ++(int)there's nothing except an opening brace on line 53. This function starts on line 52.
Any help is appreciated!!