samedi 22 octobre 2016

Class "classname" has no member "function"

So I have a school project where I have to make a random dungeon crawler. I am quite new to C++ and I have an error, I know what the problem is but I don't know how to solve it exactly.

Here is the thing:

In my Chamber class I want a pointer to the DungeonLayer class. But I can't include DungeonLayer.h to Chamber.h because DungeonLayer.h already has Chamber.h included so I get an exception.

How can I make it so DungeonLayer class is accessable from the Chamber class?

Files:

DungeonLayer.h

#pragma once
#include <vector>
#include "Chamber.h"

class DungeonLayer {

public:
    DungeonLayer(std::string text, int l);
    Chamber findChamber(int x2, int y2);
    std::vector<Chamber> chambers;
    void generateDungeonLayer();
    bool chamberExists(int x2, int y2);
};

Chamber.h

#pragma once
#include <vector>
#include "Enemy.h"
#include "Hero.h"

class DungeonLayer {

};

class Chamber {

public:
    Chamber(std::vector<Chamber>* dungeonLayer, int ammountOfChambers);
    DungeonLayer *layer;
    Chamber *nextChamber;
    .......
    Chamber* Chamber::getNextChamber();
    void moveToChamber();

private:
    bool visited;
};

Whenever I set the pointer of the DungeonLayer (layer) and I want to call a function on it it gives the error:

"class "DungeonLayer" has no member "findChamber"   CPPAssessment   Chamber.cpp"

This is obvious because the class DungeonLayer in Chamber.h has nothing in it. But how can I make it so DungeonLayer is accessable from Chamber?

Aucun commentaire:

Enregistrer un commentaire