Witam,
Mam pewien problem, mianowicie po stworzeniu konstruktora klasy Postać, przy dziedziczącej z niej klasie Lokacja występuje błąd: "error: no matching function for call to 'Postac::Postac()". Znalazłem na forum coś takiego, chyba to jest rozwiązanie problemu, ale nie wiem jak to zapisać aby działało:
Jeśli zdefiniujesz w klasie konstruktor z argumentami, to automatycznie traci ona konstruktor domyślny - musisz go ręcznie stworzyć. Obiekt klasy pochodnej wywołuje automatycznie konstruktor domyślny klasy bazowej, ale tylko wtedy, gdy istnieje - gdy go nie ma, musisz go stworzyć lub wywołać jawnie inny konstruktor w liście inicjalizacyjnej.
Tutaj kawałki kodu:
Klasa Postać:
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
class Postac
{
public:
int zdrowie;
int mana;
int sila;
int zrecznosc;
int talent_mag;
int akt_zdrowie;
int akt_mana;
int lvl;
int exp;
string klasa;
Postac (int, int, int, int, int, int, int, int, int, string);
void statystyki();
void wybierz_klase();
};
Konstruktor klasy Postać:
Postac::Postac(int hp, int mp, int st, int zr, int tm, int a_z, int a_m, int lv, int ex, string k)
{
zdrowie = hp;
mana = mp;
sila = st;
zrecznosc = zr;
talent_mag = tm;
akt_zdrowie = a_z;
akt_mana = a_m;
lvl = lv;
exp = ex;
klasa = k;
}
Klasa Lokacja:
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
class Lokacja :public Postac
{
public:
void staty();
};