I cannot for the life of me work out why this isn’t working… Can’t compile, keep getting an error “no matching function for call to ‘Duty::Duty()'” for the line with the changeDuty constructor. I think it thinks I’m trying to call one of the Duty class constructors? But I just want to pass in a Duty class object!
class Duty
{
string Chore;
string Member;
public:
Duty(string dutyInfo);
Duty(string chore, string member) {Chore = chore; Member = member;}
};
class changeDuty
{
Duty Original;
public:
changeDuty(Duty original) {Original = original;}
};
After perusing similar questions, I’ve tried using
changeDuty(Duty& original) {Original = original;}
and
changeDuty(const Duty& original) {Original = original;}
Still no dice. What am I doing wrong?
This first default-constructs
Original, then reassigns it. But there is no default constructor, so it is an error. What you wanted was:which copy-constructs
Original.