当我遇到运算符重载问题时,我正要完成我的任务,错误说
错误 1 错误 C2661: 'Date::Date' : 没有重载函数需要 3 个参数 c:\users\86\documents\visual studio 2010\projects\assignmnent 3 840\assignmnent 3 840\date.cpp 137
2 IntelliSense:构造函数“Date::Date”的实例不匹配参数列表 c:\users\86\documents\visual studio 2010\projects\assignmnent 3 840\assignmnent 3 840\date.cpp 137
及其标记日期返回 Date(mt,dy,yr); 请帮忙,我已经尝试这个东西 3 个小时了。
这是代码
////////////////////date.h
#include <iostream>
using namespace std;
class Date
{
private:
int day,month,year ;
public:
Date ();
void setValues();
// int getValues() ;
Date operator=(const Date &);
//
Date(const Date &);
//
//friend Date operator+(Date a,Date b);
Date operator-(const Date &);
friend bool operator>(Date a, Date b);
friend bool operator==(Date a, Date b);
friend ostream &operator<<(ostream &out, Date a);
friend istream &operator>>(istream &in, Date &a);
//
};
/////////////////date.cpp
#include <iostream>
using namespace std;
class Date
{
private:
int day,month,year ;
public:
Date ();
void setValues();
// int getValues() ;
Date operator=(const Date &);
//
Date(const Date &);
//
//friend Date operator+(Date a,Date b);
Date operator-(const Date &);
friend bool operator>(Date a, Date b);
friend bool operator==(Date a, Date b);
friend ostream &operator<<(ostream &out, Date a);
friend istream &operator>>(istream &in, Date &a);
//
};
////////driver.cpp
//test.cpp
#include "date.h"
#include <iostream>
using namespace std;
int main()
{
Date date1;
Date date2 = date1; //copy constructor called
cout << "Initial date values\n";
cout << "Date 1 is ";
cout << date1 << endl;
cout << "Date 2 is ";
cout << date2 << endl;
cout << "Enter a date no earlier than 1800\n";
cin >> date1;
cout << "Enter another date no earlier than 1800\n";
cin >> date2;
cout << "Revised date values\n";
cout << "Date 1 is ";
cout << date1 << endl;
cout << "Date 2 is ";
cout << date2 << endl;
if (date1 == date2)
cout << "The two input dates are the same\n";
else if (date1 > date2)
{
cout << "Date 1 is later in time than Date 2 by ";
Date temp = date1 - date2;
cout << temp << endl;
}
else
{
cout << "Date 2 is later in time than Date 1 by ";
Date temp = date2 - date1;
cout << temp << endl;
}
//Date date3, date4;
//date4 = date3 = date2; //overloaded assignment operator called
//cout << "After the assignment date4 = date3 = date2\n";
//cout << " Date 3 is " << date3 << " and Date 4 is " << date4 << endl;
return 0;
}