• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Klasy abstrakcyjne i destruktor wirtualny

0 głosów
239 wizyt
pytanie zadane 7 czerwca 2020 w C i C++ przez arnoldziks123 Nowicjusz (120 p.)

Witam, Mam problem z poniższym kodem . Z góry dziękuję  za pomoc.

C:\Users\Mateusz_2\Desktop\programy\rozdz14 zad 4\person.h|68|undefined reference to `PokerPlayer::~PokerPlayer()'|

 

C:\Users\Mateusz_2\Desktop\programy\rozdz14 zad 4\person.h|68|undefined reference to `Gunslinger::~Gunslinger()'|

 

#ifndef PERSON_H_
#define PERSON_H_
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <ctime>



using std::string;

class Person
{
private:
    string imie;
protected:
    virtual void dane() const;
    virtual void Get();

public:
    Person(): imie("Brak"){}
    Person(const string & name) : imie(name){}
    virtual ~Person()=0;
    virtual void show() const=0;
    virtual void setall()=0;
};

class Gunslinger : virtual public Person
{
private:
    double czas;
    int naciecia;
protected:
    virtual void dane() const;
    virtual void Get();
public:
    Gunslinger() :Person(), czas(0), naciecia(0) {}
    Gunslinger(const string & name,  double time, int nac) : Person(name), czas(time), naciecia(nac) {}
    Gunslinger(const Person & p, double time, int nac) : Person(p), czas(time), naciecia(nac) {}
    ~Gunslinger();
    double draw() const {return czas;}
    void show() const;
    void setall();


};

class PokerPlayer : public virtual Person
{
private:
    int liczba;
protected:
      virtual void Get();
    virtual void dane() const;

public:
    PokerPlayer(): Person(), liczba(0){}
    PokerPlayer(const Person & p, int licz): Person(p), liczba(licz){}
    PokerPlayer(const string & name, int licz) : Person(name), liczba(licz){}
     ~PokerPlayer();
    int  draw() const;
    void show() const;
    void setall();

};

class BadDude : public Gunslinger, public PokerPlayer
{
     virtual void dane() const;
         virtual void Get();
public:
    BadDude() : Gunslinger(), PokerPlayer() {}
    BadDude(const string & name,  double time, int nac, int licz) : Person(name), Gunslinger(name, time, nac), PokerPlayer(name, licz){}
    BadDude(const Gunslinger & g, int licz ): Person(g), Gunslinger(g), PokerPlayer(g,licz){}
    BadDude(const Person & p, double time, int nac, int licz) :Person(p), Gunslinger(p,time,nac), PokerPlayer(p, licz){}
    BadDude(const PokerPlayer & pp, double time, int nac): Person(pp), Gunslinger(pp,time, nac), PokerPlayer(pp){}
    double Gdraw() const;
    int Cdraw() const;
    void show() const;
    void setall();


};



#endif // PERSON_H_
#include <iostream>
#include "person.h"
#include <string>
#include <cstdlib>
#include <cstdio>
#include <ctime>



using namespace std;


     void Person::dane() const
     {
         cout<<"Imie i nazwisko: "<<imie;
     }
     void Person::Get()
     {
         cout<<"Podaj imie i nazwisko: ";
         getline(cin, imie);
         while(cin.get() != '\n')
            continue;
     }


    void Gunslinger::dane() const
    {
        cout<<"\nCzas wyciagania rewolweru: "<<czas;
        cout<<"\nLiczba naciec na rewolwerze: "<<naciecia;
    }
    void Gunslinger::Get()
    {
        cout<<"\nPodaj czas wyciagania rewolweru: ";
        cin>>czas;
        cout<<"\nPodaj liczbe naciec na rewolwerze: ";
        cin>>naciecia;
    }
    void Gunslinger::show() const
    {
        cout<<"\nRewolwerwiec\n ";
        Person::dane();
        dane();
    }
    void Gunslinger::setall()
    {
        Person::Get();
        Get();
    }


    void PokerPlayer::Get()
    {
        Person::Get();
    }
    void PokerPlayer::dane() const
    {
        cout<<"Numer karty: "<<liczba;
    }
    int  PokerPlayer::draw() const
    {
        srand(time(NULL));
      return rand()%52+1;
    }
    void PokerPlayer::setall()
    {
        Get();
    }
    void PokerPlayer::show() const
    {
        cout<<"\nPokerzysta\n";
        Person::dane();
        dane();
    }

     void BadDude::dane() const
     {
         Gunslinger::dane();
         PokerPlayer::dane();
     }
     void BadDude::Get()
     {
         Gunslinger::Get();
         PokerPlayer::Get();
     }
    double BadDude::Gdraw() const
    {
        return Gunslinger::draw();
    }
    int BadDude::Cdraw() const
    {
        return PokerPlayer::draw();
    }
    void BadDude::show() const
    {
        cout<<"\nBadDude\n";
        dane();
        cout<<"\nCzas wyciagnania rewolweru: "<<Gdraw();
        cout<<"\nLosowa karta od 1 do 52: "<<Cdraw();
    }
    void BadDude::setall()
    {
        Get();
    }
#include  <iostream>
#include "person.h"

using namespace std;

int main()
{
    const int SIZE = 5;
    Person * Tab[SIZE];
    int ct;
    for (ct = 0; ct <SIZE; ct++)
    {
        int choice;
        cout << "Kim chcesz byc???? :D\n"
                "1: pokerzysta, 2: rewolwerowiec, 3: Zly gosc!, 4: wyjscie\n";
        while (!(cin >> choice) && (choice == 1 || choice == 2 || choice == 3 || choice == 4))
        {
            cout <<"Wpisz 1 lub 2 lub 3 lub 4!";
        }
        if (choice == 4)
            break;
        switch(choice)
        {
           case 1 : Tab[ct] = new PokerPlayer; //Tutaj jest blad
                break;
            case 2 : Tab[ct] = new Gunslinger;
                break;
            case 3 : Tab[ct] = new BadDude;
                break;
        }
        cin.get();
        Tab[ct]->setall();
    }
    cout <<"\nLista bohaterow:\n";
    int i;
    for (i = 0; i < ct;i++)
    {
        cout<<endl;
        Tab[i]->show();
    }
    for (i = 0; i < ct; i ++)
        delete Tab[i];

    cin.get();
    cin.get();
    return 0;
}

 

1 odpowiedź

0 głosów
odpowiedź 8 czerwca 2020 przez j23 Mędrzec (195,240 p.)

Zdefiniuj destruktory PokerPlayer::~PokerPlayer i Gunslinger::~Gunslinger.

Podobne pytania

0 głosów
2 odpowiedzi 1,176 wizyt
pytanie zadane 8 grudnia 2018 w C i C++ przez dawid2002 Mądrala (5,190 p.)
0 głosów
1 odpowiedź 598 wizyt
0 głosów
2 odpowiedzi 2,705 wizyt
pytanie zadane 11 marca 2018 w C i C++ przez Utau Użytkownik (900 p.)

93,425 zapytań

142,421 odpowiedzi

322,646 komentarzy

62,785 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

VMware Cloud PRO - przenieś swoją infrastrukturę IT do chmury
...