Mam taki kod:
Organizm.h:
#pragma once
//#include "Swiat.h"
#include <iostream>
class Swiat;
class Organizm
{
private:
struct polozenie
{
unsigned int x;
unsigned int y;
};
protected:
short sila, inicjatywa;
Swiat *mySwiat;
public:
polozenie pozycja;
char symbol = '.';
Organizm();
Organizm(short sila, short inicjatywa, Swiat& sw);
virtual void akcja() = 0;
};
Organizm.cpp:
#include "Organizm.h"
#include "Swiat.h"
Organizm::Organizm()
{
inicjatywa = 0;
sila = 0;
pozycja.x = 0;
pozycja.y = 0;
mySwiat = nullptr;
}
Organizm::Organizm(short sila, short inicjatywa, Swiat& sw)
{
mySwiat = &sw;
this->sila = sila;
this->inicjatywa = inicjatywa;
}
void Organizm::akcja()
{
//Tutaj jest ok
mySwiat->getX();
}
Zwierze.h:
#pragma once
#include <iostream>
#include "Organizm.h"
class Zwierze : public Organizm
{
public:
Zwierze(short sila, short inicjatywa, Swiat& sw);
Zwierze();
};
Zwierze.cpp:
#include "Zwierze.h"
Zwierze::Zwierze(short sila, short inicjatywa, Swiat& sw) : Organizm(sila, inicjatywa, sw)//, sw) , Swiat& sw)
{
//expression must have class type but it has type
mySwiat.mapa;
}
Swiat.h:
#pragma once
#include <iostream>
#include "organizm.h"
class Swiat
{
private:
struct pole
{
unsigned int id = 0;
Organizm* organizmy;
};
unsigned int x, y;
public:
Swiat(unsigned int x=0, unsigned int y=0);
~Swiat();
pole** mapa;
};
Przy mySwiat.mapa; w pliku Zwierze.cpp pojawia się błąd "expression must have class type but it has type". Dlaczego?