你好,当我试图编译这个时,我在Mysz.cpp
中遇到了错误:
error C2039: 'inicjatywa' : is not a member of 'Mysz'
error C2039: 'sila' : is not a member of 'Mysz'
error C2039: 'typ' : is not a member of 'Mysz'
error C2039: 'symbol' : is not a member of 'Mysz'
etc...
Organizm.h
#include "header.h"
class Swiat;
class Organizm
{
protected:
string typ;
char symbol;
int sila,inicjatywa, x,y;
Swiat *ref;
public:
Organizm() { symbol = ' '; };
}
Zwierze.h
#include "Organizm.h"
class Zwierze: public Organizm
{
public:
Zwierze() {};
public:
virtual int kolizja(Organizm& org) override
{
if(this->typ==org.getTyp()){return roz;}
else if(this->sila<org.getSila())return win;
else return loose;
};
virtual char akcja() override
{
char tab[4]={'p','d','g','l'};
int kierunek=rand() % 4;
return tab[kierunek];
};
};
Mysz.h
#ifndef MYSZ_H
#define MYSZ_H
class Swiat;
class Mysz: public Zwierze
{
public:
Mysz (int x,int y,Swiat *swiat);
public:
int kolizja(Organizm& org);
};
#endif
Mysz.cpp
#include "Mysz.h"
#include "Swiat.h"
Mysz::Mysz(int x,int y,Swiat *swiat)
{
this->typ="Mysz";
this->symbol='M';
this->sila=1;
this->inicjatywa=6;
this->x=x;
this->y=y;
this->ref=swiat;
};
答案 0 :(得分:0)
我认为在Mysz.h
中,由于继承Zwierze.h
,您没有包含public Zwierze
。
在使用继承的成员变量编译错误之前,我原本期望编译错误Zwierze
。你没有收到这样的错误吗?