Reputation: 125
As you can see I am trying to add 7 days to "Days" to Class "MyAge", but it gives me one error:
no matching function for call to MyAge::MyAge(int , int&, int&)
Why this is happening? While you answer this question try to be more noob specific.
Sorry for my bad english, I am an Indian. here is my code.
#include<iostream>
using namespace std;
class MyAge
{
private:
int Days;
int Months;
int Years;
int DaysToAdd;
public:
void SetAge(int InputDays,int InputMonths,int InputYears)
{
Years= InputYears;
Months=InputMonths;
Days=InputDays;
}
MyAge operator + (int Add)
{
MyAge Blah (Days + Add,Months,Years);
return Blah;
}
void Display()
{
cout <<"Your age after increment is"<<Years<<"years"<<Months<<"Months"<<Days<<"Days";
}
};
int main()
{
MyAge BirthDay;
BirthDay.SetAge(10,11,19);
MyAge NameDay(BirthDay+7);
NameDay.Display();
return 0;
}
Upvotes: 0
Views: 98
Reputation: 171097
You're trying to call a 3-parameter constructor, but you don't have one. You could add it, or change the implementation of operator +
like this:
MyAge operator + (int Add)
{
MyAge Blah;
Blah.SetAge(Days + Add, Months, Years);
return Blah;
}
Upvotes: 1