L
Latina
Hi, I am doing a program using overloded operators but I am getting
some error,
Can some one help please.
Here is my code:
#include<iostream>
#include<string.h>
#include<cctype>
using namespace std;
class Date
{
private:
int mon;
int day;
int year;
string m;
public:
friend istream& operator>>(istream& is, Date& d1);
friend ostream &operator<<(ostream &os, const Date &d1);
int operator-(Date);
bool operator>(Date);
int distinction(Date);
};
ostream &operator<<(ostream &out, const Date &d)
{ <--error(a function-definition is not allowed here
before '{' token) and (expected `,' or `;' before '{' token)
out<<d.mon<<"/"<<d.day<<"/"<<d.year;
return out;
}
bool Date:
perator >(Date d)
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
int diff = distinction(d);
if(diff < 0)
return true;
else
return false;
}
int Date:
perator -(Date d)
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
return distinction(d);
}
int Date::distinction(Date t)
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
int total = 0;
total = (year - t.year) * 365;
total += (month - t.month) * 30.5;
total += (day - t.day);
total += (year - t.year) / 4;
if(total<0)
total *= -1;
return total;
}
Thanks
some error,
Can some one help please.
Here is my code:
#include<iostream>
#include<string.h>
#include<cctype>
using namespace std;
class Date
{
private:
int mon;
int day;
int year;
string m;
public:
friend istream& operator>>(istream& is, Date& d1);
friend ostream &operator<<(ostream &os, const Date &d1);
int operator-(Date);
bool operator>(Date);
int distinction(Date);
};
ostream &operator<<(ostream &out, const Date &d)
{ <--error(a function-definition is not allowed here
before '{' token) and (expected `,' or `;' before '{' token)
out<<d.mon<<"/"<<d.day<<"/"<<d.year;
return out;
}
bool Date:
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
int diff = distinction(d);
if(diff < 0)
return true;
else
return false;
}
int Date:
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
return distinction(d);
}
int Date::distinction(Date t)
{ <--error(a function-definition is not allowed here before
'{' token) and (expected `,' or `;' before '{' token)
int total = 0;
total = (year - t.year) * 365;
total += (month - t.month) * 30.5;
total += (day - t.day);
total += (year - t.year) / 4;
if(total<0)
total *= -1;
return total;
}
Thanks