I have two headers which are giving me trouble at the moment.These headers include each other and use types of one another in their implementations. The list of errors is huge,and they dont make sense.For example errors. I am 99% sure the problem has to do something with forward declarations,but then i get incomplete types errors.First .h looks like this:
#ifndef CHESS_SRC_POSITION_H
#define CHESS_SRC_POSITION_H
#include "material.h"
class Position {
public:
int x, y;
Position() = default;
Position(int x, int y): x(x) , y(y) {}
bool operator==(const Position& other) const noexcept {
return x == other.x && y == other.y;
}
bool IsOccupied(const std::vector<Material*>& enemy); // This thing gives me another 3 pages of errors
};
#endif // CHESS_SRC_POSITION_H
and the second class
#ifndef CHESS_SRC_PIECES_MATERIAL_H
#define CHESS_SRC_PIECES_MATERIAL_H
#include <string> // std::string
#include <vector> // std::vector
#include "color.h" // Color
#include "position.h" // Position
class Material {
public:
Material(Position initPostion, Color color, int points);
bool MoveMaterial(Position newPosition, const std::vector<Material*>& enemy);
virtual std::vector<Position>
AvailableMoves(const std::vector<Material*>& enemy) = 0;
//-----------Getters&Setters--------
std::string GetColor();
Position GetPosition();
//Change later
bool PositionOccupied(const std::vector<Material*> enemy);
virtual int value() const noexcept = 0;
protected:
bool InBoard(Position pos);
const Color color_;
Position position_;
int points_;
};
#endif // CHESS_SRC_PIECES_MATERIAL_H
I try to use the Google Style for c++ and they recommend to avoid using forward declarations,but use includes instead.I have my guards so,what am i doing wrong?