1

Suppose I have:

class Human {
    string choice;
public:
    Human(string);
};

class Computer {
    string compChoice;
public:
    Computer(string);
};

class Refree : public Human, public Computer {
public:
    string FindWinner();
};

int main() {
    Human* H1 = new Human("name");
    Computer* C1 = new Computer("AI");
    Refree* R1 = new Refree();
}

This code fails to compile with:

 In function 'int main()':
error: use of deleted function 'Refree::Refree()'
note: 'Refree::Refree()' is implicitly deleted because the default definition  would be ill-formed:
error: no matching function for call to 'Human::Human()'
note: candidates are:
note: Human::Human(std::string)
note:   candidate expects 1 argument, 0 provided

Why does this fail, and how can I construct a pointer to Refree?

Barry
  • 286,269
  • 29
  • 621
  • 977

1 Answers1

3

Since Human and Computer have user-declared constructors that take an argument, their default constructors are implicitly deleted. In order to construct them, you need to give them an argument.

However, you are trying to construct Refree without any arguments - which implicitly tries to construct all of its bases without any arguments. That is impossible. Setting aside whether or not it makes sense for something to be both a Human and a Computer, at the very least you have to do something like:

Refree()
: Human("human name")
, Computer("computer name")
{ }

More likely, you want to provide a constructor that takes one or both names, e.g.:

Refree(const std::string& human, const std::string& computer)
: Human(human)
, Computer(computer)
{ }
Barry
  • 286,269
  • 29
  • 621
  • 977