0

Hello when i trying to compile this i've got errors in 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;
};
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
user2965470
  • 5
  • 1
  • 1
  • 4
  • 1
    You can not access these members of `class Organizm` since they are protected. They are in scope only for the immediate next layer of inheritance (e.g. `class Zwierze`). – πάντα ῥεῖ Apr 23 '14 at 16:11
  • But when I've made them public the same error appeared. Is there no way to make them inherit? – user2965470 Apr 23 '14 at 16:17
  • I don't believe the scope is limited to just the immediate inheritance for public inheritance (note that I am talking about the access specifier for inheritance. E.g `public Zwierze`). http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance-in-c – ap-osd Apr 23 '14 at 16:46

1 Answers1

0

I think in Mysz.h you have not included Zwierze.h which is required because of inheritance public Zwierze.

I would have expected a compile error with Zwierze before the compilation error with the inherited member variables. Did you not get such an error?

ap-osd
  • 2,624
  • 16
  • 16