Witam, mam problem z kompilacją projektu, czy mógłby ktoś rzucić na to okiem? Nie kompiluje w MV.
#include <cstdlib>
#include <string>
#include <iostream>
#pragma warning( disable : 4996)
#pragma warning( disable : 4267)
using namespace std;
// funkcja do alokowania dynamicznego char
char* alokuj(char* txt)
{
char* nazwa;
int dl_tekstu = strlen(txt);
try {
nazwa = new char[dl_tekstu+1];
}
catch (bad_alloc)
{
cerr << "Blad alokacji"<< endl;
}
return nazwa;
}
class Ksiazka;
class Czytelnik;
/* ---------------------- BIBLIOTEKA ----------------------------------*/
class Biblioteka
{
char* nazwa;
public:
friend ostream& operator<< (ostream &ob,Biblioteka &bl); //przeciazenie <<
void zwroc(Ksiazka &ks, Czytelnik &cz);
void wypozycz(Ksiazka &ks, Czytelnik &cz);
Biblioteka (char *nzw); //konstruktor
~Biblioteka() { delete [] nazwa; nazwa=NULL;} //destruktor
};
//konstruktor
Biblioteka::Biblioteka(char *nzw)
{
nazwa = alokuj(nzw);
strcpy(nazwa, nzw);
}
ostream& operator<< (ostream &ob,Biblioteka &bl)
{
return ob <<"[Biblioteka] Nazwa: " << bl.nazwa <<endl;
}
/* ---------------------- GATUNEK LITERACKI ----------------------------------*/
class Gatunek
{
char* nazwa_gatunku;
public:
Gatunek(char *txt="brak");
~Gatunek() { delete [] nazwa_gatunku; nazwa_gatunku=NULL; }
char* dajgat() { return nazwa_gatunku; }
};
Gatunek::Gatunek(char *txt)
{
nazwa_gatunku = alokuj(txt);
strcpy(nazwa_gatunku, txt);
}
/* ---------------------- TOM ----------------------------------*/
class Tom
{
int liczba_tomow;
public:
int dajLiczba_tomow() { return liczba_tomow; }
Tom(int l = 0) : liczba_tomow(l) {};
~Tom() {};
};
/* ---------------------- KSIAZKA ----------------------------------*/
class Ksiazka : public Gatunek
{
Tom t; //kompozycja
char *tytul;
int rok_wydania;
int liczba_stron;
const int liczba_sztuk; // liczba sztuk do wypożyczenia
int poz_liczba_sztuk; // liczba sztuk pozostałych do wypożyczenia
double cena;
public:
static int liczba_ksiazek;
friend void Biblioteka::zwroc(Ksiazka &ks, Czytelnik &cz);
friend void Biblioteka::wypozycz(Ksiazka &ks, Czytelnik &cz);
friend ostream& operator<< (ostream &ob,Ksiazka &ks); //przeciazenie <<
int wypozyczen() { return (liczba_sztuk - poz_liczba_sztuk); }
Ksiazka(char* txt, char *gat, int rok=2012, int liczba = 150, double cena = 10, int sztuk = 1);
Ksiazka(const Ksiazka &ks); //konstruktor kopiujacy
~Ksiazka() { delete [] tytul; tytul=NULL; liczba_ksiazek--; } //destruktor
};
//konstruktor kopiujacy
Ksiazka::Ksiazka(const Ksiazka &ks)
: rok_wydania(ks.rok_wydania), liczba_stron(ks.liczba_stron), cena(ks.cena), liczba_sztuk(ks.liczba_sztuk), poz_liczba_sztuk(ks.poz_liczba_sztuk)
{
tytul = alokuj(ks.tytul);
strcpy(tytul, ks.tytul);
}
//konstruktor
Ksiazka::Ksiazka(char* txt, char *gat, int rok, int liczba, double cena, int sztuk)
: rok_wydania(rok), t(liczba), cena(cena), liczba_sztuk(sztuk), poz_liczba_sztuk(sztuk), Gatunek(gat)
{
tytul = alokuj(txt);
strcpy(tytul, txt);
liczba_ksiazek++;
}
//przeciazenie operatora <<
ostream& operator<< (ostream &ob,Ksiazka &ks)
{
return ob <<"[Ksiazka] Tytul: " << ks.tytul << ", gatunek: " << ks.dajgat() <<", rok wydania: "<< ks.rok_wydania <<", liczba tomow: " << t.dajLiczba_tomow() << ", cena: " << ks.cena << " zl" << endl;
}
/* ---------------------- CZYTELNIK ----------------------------------*/
class Czytelnik
{
char *imie_nazwisko;
int liczba_lat;
int liczba_wypoz_ks; //liczba wypozyczonych ksiazek
public:
friend void Biblioteka::zwroc(Ksiazka &ks, Czytelnik &cz);
friend void Biblioteka::wypozycz(Ksiazka &ks, Czytelnik &cz);
friend ostream& operator<< (ostream &ob,Czytelnik &cz); //przeciazenie <<
int wypozyczen() { return liczba_wypoz_ks; }
Czytelnik(char *in, int lata = 15); //konstruktor
Czytelnik(const Czytelnik &cz); //konstruktor kopiujacy
~Czytelnik() { delete [] imie_nazwisko; imie_nazwisko=NULL;} //destruktor
};
//konstruktor kopiujacy
Czytelnik::Czytelnik(const Czytelnik &cz) : liczba_lat(cz.liczba_lat), liczba_wypoz_ks(cz.liczba_wypoz_ks)
{
imie_nazwisko = alokuj(cz.imie_nazwisko);
strcpy(imie_nazwisko, cz.imie_nazwisko);
}
//konstruktor
Czytelnik::Czytelnik(char *in, int lata) : liczba_lat(lata), liczba_wypoz_ks(0)
{
imie_nazwisko = alokuj(in);
strcpy(imie_nazwisko, in);
}
//przeciazenie operatora <<
ostream& operator<< (ostream &ob,Czytelnik &cz)
{
return ob <<"[Czytelnik] Imie nazwisko: " << cz.imie_nazwisko << ", lat: "<< cz.liczba_lat <<", wypozyczonych ksiazek: " << cz.liczba_wypoz_ks <<endl;
}
void Biblioteka::wypozycz(Ksiazka &ks, Czytelnik &cz)
{
if(ks.poz_liczba_sztuk>0)
{
ks.poz_liczba_sztuk--;
cz.liczba_wypoz_ks++;
cout << "[Biblioteka] Wypozyczono ksiazke \"" << ks.tytul << "\" czytelnikowi \"" << cz.imie_nazwisko << "\" \n";
}
else
cout << "[Biblioteka] Brak egzemplarza do wypozyczenia ksiazki \"" << ks.tytul << "\" czytelnikowi \"" << cz.imie_nazwisko << "\" \n";
}
void Biblioteka::zwroc(Ksiazka &ks, Czytelnik &cz)
{
if(ks.poz_liczba_sztuk!=ks.liczba_sztuk)
{
ks.poz_liczba_sztuk++;
cz.liczba_wypoz_ks--;
cout << "[Biblioteka] Zwrot ksiazki \"" << ks.tytul << "\" przez czytelnika \"" << cz.imie_nazwisko << "\" \n";
}
else
cout << "[Biblioteka] Brak egzemplarzy do zwrocenia ksiazki \"" << ks.tytul << "\", czytelnik \"" << cz.imie_nazwisko << "\" \n";
}
/* -------------------------------------------------------------------
---------------------- MAIN ----------------------------------
------------------------------------------------------------------- */
int Ksiazka::liczba_ksiazek = 0;
int main()
{
Ksiazka Metro("Metro 2033", "SF", 2010, 1, 45.5, 3);
cout << Metro;
Czytelnik Ja("Imie Nazwisko", 22);
cout << Ja << Metro;
Biblioteka Miejska("WCK");
cout << Miejska;
Miejska.wypozycz(Metro, Ja);
cout << Ja << Metro;
Miejska.zwroc(Metro, Ja);
return 0;
}
ERROR LIST:
Error 1 error C2065: 't' : undeclared identifier c:...\source1.cpp 126 1 ...
Error 2 error C2228: left of '.dajLiczba_tomow' must have class/struct/union c:...\source1.cpp 126 1 ...
3 IntelliSense: identifier "t" is undefined c:...Source1.cpp 126 143 ...
4 IntelliSense: member "Ksiazka::poz_liczba_sztuk" (declared at line 89) is inaccessible c:...Source1.cpp 172 9 ...
5 IntelliSense: member "Ksiazka::poz_liczba_sztuk" (declared at line 89) is inaccessible c:...Source1.cpp 174 6 ...
6 IntelliSense: member "Czytelnik::liczba_wypoz_ks" (declared at line 135) is inaccessible c:...Source1.cpp 175 6 ...
7 IntelliSense: member "Ksiazka::tytul" (declared at line 85) is inaccessible c:...Source1.cpp 176 55 ...
8 IntelliSense: member "Czytelnik::imie_nazwisko" (declared at line 133) is inaccessible c:...Source1.cpp 176 91 ...
9 IntelliSense: member "Ksiazka::tytul" (declared at line 85) is inaccessible c:...Source1.cpp 179 76 ...
10 IntelliSense: member "Czytelnik::imie_nazwisko" (declared at line 133) is inaccessible c:...Source1.cpp 179 112 ...
11 IntelliSense: member "Ksiazka::poz_liczba_sztuk" (declared at line 89) is inaccessible c:...Source1.cpp 184 9 ...
12 IntelliSense: member "Ksiazka::liczba_sztuk" (declared at line 88) is inaccessible c:...Source1.cpp 184 32 ...
13 IntelliSense: member "Ksiazka::poz_liczba_sztuk" (declared at line 89) is inaccessible c:...Source1.cpp 186 6 ...
14 IntelliSense: member "Czytelnik::liczba_wypoz_ks" (declared at line 135) is inaccessible c:...Source1.cpp 187 6 ...
15 IntelliSense: member "Ksiazka::tytul" (declared at line 85) is inaccessible c:...Source1.cpp 188 49 ...
16 IntelliSense: member "Czytelnik::imie_nazwisko" (declared at line 133) is inaccessible c:...Source1.cpp 188 89 ...
17 IntelliSense: member "Ksiazka::tytul" (declared at line 85) is inaccessible c:...Source1.cpp 191 73 ...
18 IntelliSense: member "Czytelnik::imie_nazwisko" (declared at line 133) is inaccessible c:...Source1.cpp 191 107 ...