Рефери. cpp: 10: 18: ошибка: нет подходящей функции для вызова функции «Human :: Human ()» Referee :: Referee () - PullRequest
0 голосов
/ 06 апреля 2020

Я новичок в c ++, и у меня возникли проблемы с наследованием, кто-нибудь знает, почему я получаю эту ошибку? (это единственная ошибка, которую я получаю при компиляции).

Я скомпилировал с помощью g ++ -o. Также я заранее сожалею, если я делаю много вещей здесь неправильно, я очень плохо знаком с c ++. > _ <Пожалуйста, дайте мне знать, как я могу сделать мой код лучше или эффективнее. </p>

computer.h

#ifndef RPS_H
#define RPS_H
#include <iostream>
#include <string>
#include <stdio.h>


class Computer 
{
    public: 
    Computer(std::string);
    ~Computer();
    char charc;
};

#endif

human.h

#ifndef HUMAN_H
#define HUMAN_H
#include <iostream>
#include <string>
#include <stdio.h>


class Human 
{
    public: 
    Human(std::string);
    ~Human();
    char charh;

};

#endif

referee.h

#ifndef REFEREE_H
#define REFEREE_H
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"



class Referee : public Human{
    public: 
    Referee();
    ~Referee();
    bool Winneris();
};

#endif 

Компьютер. cpp

#include <iostream>
#include <string>
#include <stdio.h>
#include "computer.h"

using namespace std;

Computer::Computer(string char_c)
{
}
Computer::~Computer()
{
}

Человек. cpp

#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"

using namespace std;

Human::Human(string char_h){
char_h=charh;
cout<<"r/p/s?"<<endl;
cin>>charh;
}

Human::~Human()
{
}

Рефери. cpp

#include <iostream>
#include <string>
#include <stdio.h>
#include "referee.h"

using namespace std;

Referee::Referee(){
}

bool Referee::Winneris(){

if (charh=='r'){
    cout<<"draw"<<endl;
}
else if(charh=='p'){
    cout<<"Victory!"<<endl;
}
else if(charh=='s')
{
    cout<<"Defeat"<<endl;
}
return 0;
}

Referee::~ReReferee(){
}

main. cpp

#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
#include "computer.h"
#include "referee.h"


using namespace std;
string char_h;
string char_c;
// main program
int main()
{

    Human *round1h;

    round1h = new Human(char_h);

    Computer *round1c;

    round1c = new Computer(char_c);

    Referee *round1r;

    round1r = new Referee();

    round1r -> Winneris();
}

1 Ответ

0 голосов
/ 06 апреля 2020

Когда вы написали параметризованный конструктор в соответствующих классах. Вы создали объекты класса, которые вызывают конструктор по умолчанию, который не принимает параметров.

Вы также должны определить конструктор по умолчанию в соответствующих классах.

Human::Human()
{}
Computer::Computer()
{}
Referee::Referee()
{}

Типы конструкторов

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...