[C++] błąd przy kompilacji

0

Witam, napisałem taki kawałek programu:

#include <cstdlib>
#include <iostream>
#include <vector>
#include <string.h>
#include <conio.h>

using namespace std;

class HumanCL
{
    public:
    HumanCL() {}
    virtual void Wyswietl()=0;
};

class MaleCL : public HumanCL
{
    private:
    string name;
    string surname;
    int plec;       // 0- man, 1 female
    int age;        //wiek
    int kids[10];  // max 10 dzieciakow mozna miec
    int rodzic[2]; // 0 -> ojciec , 1 -> matka
    int partner; // -1 = brak
    public:
    MaleCL(string name, string surname, int age);
    void Wyswietl();
};

MaleCL::MaleCL(string name, string surname, int age) : HumanCL()
{
    this->name=name;
    this->surname=surname;
    this->age=age;
    plec=0;
}

void MaleCL::Wyswietl()
{
    cout << "Plec: 'M'" << endl;
    cout << "Imie: " << name << endl;
    cout << "Nazwisko " << surname << endl;
    cout << "Wiek: " << age << endl;
}

class FemaleCL : public HumanCL
{
    private:
    string name;
    string surname;
    int plec;       // 0- man, 1 female
    int age;        //wiek
    int kids[10];  // max 10 dzieciakow mozna miec
    int rodzic[2]; // 0 -> ojciec , 1 -> matka
    int partner; // -1 = brak

    public:
    FemaleCL(string name, string surname, int age);
    void Wyswietl();
};

FemaleCL::FemaleCL(string name, string surname, int age) : HumanCL()
{
    this->name=name;
    this->surname=surname;
    this->age=age;
    plec=1;
};

void FemaleCL::Wyswietl()
{
    cout << "Plec: 'F'" << endl;
    cout << "Imie: " << name << endl;
    cout << "Nazwisko " << surname << endl;
    cout << "Wiek: " << age << endl;
}

/////////////////////////////GLOWNA KLASA FAMILY//////////////////////

class FamilyCL
{
    private:
    char plec;
    string name, surname;
    int age;
    vector <HumanCL*> family;

    public:
    FamilyCL() {}
    void AddPerson();
    void Show();
};

void FamilyCL::Show()
{
    for(int i=0; i < family.size(); i++)
    {
        cout << "Indeks: " << i+1 << endl;
        family[i]->Wyswietl() << endl;
    }
}

void FamilyCL::AddPerson()
{
    cout << "Kogo chcesz dodac (M/F)?";
    plec = getch();
    cout << plec << endl;
    cout << "Podaj imie: ";
    cin >> name;
    cout << "Podaj nazwisko: ";
    cin >> surname;
    cout << "Podaj wiek: ";
    cin >> age;
    if(plec == 'M' || plec == 'm')
        family.push_back(new MaleCL(name, surname, age));
    else
        family.push_back(new FemaleCL(name, surname, age));
    cout << "Osoba zostala dodana.\n";
}

int main()
{
    FamilyCL obiekt;
    obiekt.AddPerson();
    obiekt.Show();
}
 

...i nie wiem czemu przy próbie wyświetlania danych z kontenera wyrzuca mi taki błąd:

void value not ignored as it ought to be

, a co gorsze, nie wiem jak się go pozbyć.

0

HumanCL::Wyswietl zwraca void.

Zaś ty starasz się:
family[i]->Wyswietl() << endl;

Czyli
void << endl;

Co nie jest najmądrzejszym pomysłem.

1
family[i]->Wyswietl() << endl;

Powinno być:

family[i]->Wyswietl();
cout<<endl;

edit
@4ggr35510n byłeś szybszy ;)

0
family[i]->Wyswietl() << endl;

WTF? Czy twoje Wyswietl() zwraca strumień? Albo coś co ma operator<<? Nie, zwraca void...
Plus kilka innych głupot:
http://4programmers.net/Pastebin/1667
Będzie wisiało godzinę.

0

Dziękuję :)
Zastanawiałem się czego mi tam niepoprawnie coś zwraca jak to zwykły void ;) a to głupie 'endl' . :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1