Witam
Czy ktoś wie dlaczego ten program nie może się skompilować? Wydaje mi się, że napisałem wszystko dobrze. Wypisuje mi błędy:
"In function 'int main()':|
|96|error: jump to case label [-fpermissive]
|86|error: crosses initialization of 'std::string nazwisko'
|86|error: crosses initialization of 'std::string imie'
|99|error: jump to case label [-fpermissive]
|86|error: crosses initialization of 'std::string nazwisko'
|86|error: crosses initialization of 'std::string imie'"
#include <iostream>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
using namespace std;
struct osoba
{
string imie;
string nazwisko;
int wiek;
osoba *nastepna;
osoba();
};
osoba::osoba()
{
nastepna = 0;
}
struct lista
{
osoba *pierwsza;
void dodaj_osobe (string imie, string nazwisko, int wiek);
void wyswietl_liste ();
lista();
};
lista::lista()
{
pierwsza = 0;
}
void lista::dodaj_osobe(string imie, string nazwisko, int wiek)
{
osoba *nowa = new osoba;
nowa->imie = imie;
nowa->nazwisko = nazwisko;
nowa->wiek = wiek;
if (pierwsza==0)
{
pierwsza = nowa;
}
else
{
osoba *temp = pierwsza;
while (temp->nastepna)
{
temp = temp->nastepna;
}
temp->nastepna = nowa;
nowa->nastepna = 0;
}
}
void lista::wyswietl_liste()
{
osoba *temp = pierwsza;
while (temp)
{
cout << "imie: " << temp->imie << " nazwisko: " << temp->nazwisko << endl;
temp=temp->nastepna;
}
}
int main()
{
while (true)
{
char choice;
choice=getch();
lista *baza = new lista;
switch(choice)
{
case '1':
string imie, nazwisko;
int wiek;
cout<<"Enter the name: ";
cin>>imie;
cout<<"Enter the surname: ";
cin>>nazwisko;
cout<<"Enter the age";
cin>>wiek;
baza->dodaj_osobe(imie, nazwisko, wiek);
break;
case '2':
baza->wyswietl_liste();
break;
default:
exit(0);
}
delete (baza);
return 0;
}
}