Ładny brzuch
Mam taki oto kod:
#include <iostream> using namespace std; class figura { public: void virtual narysuj() = 0; }; //****************************************************** class kwadrat : public figura { }; /*----------------------------------------*/ void kwadrat::narysuj() { cout << "rysuj kwadrat" << endl; } //****************************************************** class trojkat : public figura { }; /*----------------------------------------*/ void trojkat::narysuj() { cout << "rysuj trojkat" << endl; } //****************************************************** int main() { kwadrat k; trojkat t; figura *wskfig = &k; wskfig -> narysuj(); }
kompiluje to w Dev-cpp i wyrzuca mi bedy:
error: no `void kwadrat::narysuj()' member function declared in class `kwadrat' error: no `void trojkat::narysuj()' member function declared in class `trojkat' error: cannot declare variable `k' to be of type `kwadrat' because the following virtual functions are abstract: error: virtual void figura::narysuj()
Wyglda na to, e nie widzi tej funkcji narysuj().
Gdy deklaracje funkcji daje wewntrz klas wszystko jest ok.
Kod jest z "Symfonii C++" z t zmian, e definicje wycignem na zewnatrz.
Dlaczego mi wyrzuca te bdy i jak to naprawi?
Musisz te funkcje zadeklarowac w tych klasach, czyli w klasie narysuj:
public:
void kwadrat();
void trojkat();
Kod:
#include <iostream> using namespace std; class figura { public: void virtual narysuj() = 0; }; //****************************************************** class kwadrat : public figura { public: void narysuj(); }; /*----------------------------------------*/ void kwadrat::narysuj() { cout << "rysuj kwadrat" << endl; } //****************************************************** class trojkat : public figura { public: void narysuj(); }; /*----------------------------------------*/ void trojkat::narysuj() { cout << "rysuj trojkat" << endl; } //****************************************************** int main() { kwadrat k; trojkat t; figura *wskfig = &k; wskfig -> narysuj(); }
Wielkie dziki! Teraz dziaa
zanotowane.pl doc.pisz.pl pdf.pisz.pl zsf.htw.pl
#include <iostream> using namespace std; class figura { public: void virtual narysuj() = 0; }; //****************************************************** class kwadrat : public figura { }; /*----------------------------------------*/ void kwadrat::narysuj() { cout << "rysuj kwadrat" << endl; } //****************************************************** class trojkat : public figura { }; /*----------------------------------------*/ void trojkat::narysuj() { cout << "rysuj trojkat" << endl; } //****************************************************** int main() { kwadrat k; trojkat t; figura *wskfig = &k; wskfig -> narysuj(); }
kompiluje to w Dev-cpp i wyrzuca mi bedy:
error: no `void kwadrat::narysuj()' member function declared in class `kwadrat' error: no `void trojkat::narysuj()' member function declared in class `trojkat' error: cannot declare variable `k' to be of type `kwadrat' because the following virtual functions are abstract: error: virtual void figura::narysuj()
Wyglda na to, e nie widzi tej funkcji narysuj().
Gdy deklaracje funkcji daje wewntrz klas wszystko jest ok.
Kod jest z "Symfonii C++" z t zmian, e definicje wycignem na zewnatrz.
Dlaczego mi wyrzuca te bdy i jak to naprawi?
Musisz te funkcje zadeklarowac w tych klasach, czyli w klasie narysuj:
public:
void kwadrat();
void trojkat();
Kod:
#include <iostream> using namespace std; class figura { public: void virtual narysuj() = 0; }; //****************************************************** class kwadrat : public figura { public: void narysuj(); }; /*----------------------------------------*/ void kwadrat::narysuj() { cout << "rysuj kwadrat" << endl; } //****************************************************** class trojkat : public figura { public: void narysuj(); }; /*----------------------------------------*/ void trojkat::narysuj() { cout << "rysuj trojkat" << endl; } //****************************************************** int main() { kwadrat k; trojkat t; figura *wskfig = &k; wskfig -> narysuj(); }
Wielkie dziki! Teraz dziaa