Potrebuju vytvorit nekolik modulu mezi kterymi jsou urcite zavislosti. Problem nastava u modulu GameBoard.cpp. Kdy kompilator nepoznava ani jeden z typu Coordinate, Player, ale ani vector. Pritom potrebne soubory mam includovane... nevite, co je spatne?
Coordinate.h
#ifndef __COORDINATE_H__
#define __COORDINATE_H__
#include <iostream>
//*****************************************************************
struct Coordinate
{
Coordinate ();
Coordinate (int row, int column);
bool operator == (Coordinate other);
friend std::ostream& operator << (std::ostream & os, const Coordinate x);
int m_Row, m_Column;
};
#endif /* __COORDINATE_H__ */
Coordinate.cpp
//*****************************************************************
#include "Coordinate.h"
//*****************************************************************
Coordinate::Coordinate () { }
Coordinate::Coordinate (int row, int column)
{
m_Row = row;
m_Column = column;
}
bool Coordinate::operator == (Coordinate other)
{
return ( m_Row == other.m_Row && m_Column == other.m_Column );
}
std::ostream& operator << (std::ostream & os, const Coordinate x)
{
os << "row: " << x.m_Row << ", column: " << x.m_Column;
return os;
}
Player.h
#ifndef __PLAYER_H__
#define __PLAYER_H__
#include <string>
#include "Coordinate.h"
//*****************************************************************
class Player
{
public:
Player(const std::string name, const char symbol);
virtual ~Player();
char getSymbol() const;
std::string getName() const;
virtual Coordinate makeMove(void) = 0;
protected:
char m_Symbol;
std::string m_Name;
};
#endif /*__PLAYER_H__ */
Player.cpp
//*****************************************************************
#include "Player.h"
//*****************************************************************
//-------------------------------------
Player::Player(const std::string name, const char symbol)
{
m_Symbol = symbol;
m_Name = name;
}
Player::~Player() { }
char Player::getSymbol() const
{
return m_Symbol;
}
std::string Player::getName() const
{
return m_Name;
}
//-------------------------------------
GameBoard.h
#ifndef __GAMEBOARD_H__
#define __GAMEBOARD_H__
#include <vector>
#include "Coordinate.h"
#include "Player.h"
//*****************************************************************
class GameBoard
{
public:
GameBoard(const int row, const int column );
~GameBoard();
void writeStone(const Player & player, const Coordinate & coor);
std::vector< std::vector<char> > m_Board;
};
#endif /*__GAMEBOARD_H__ */
GameBoard.cpp
//*****************************************************************
#include "GameBoard.h"
//*****************************************************************
GameBoard::GameBoard(const int row, const int column)
{
// resize vector to size ROW and COLUMN
m_Board.resize(row);
for (auto & row : m_Board)
{
row.resize(column);
}
// fill grid with '.' which means blank symbol
for (auto & row : m_Board)
{
for (auto & symbol : row)
{
symbol = '.';
}
}
}
GameBoard::~GameBoard() { }
void GameBoard::writeStone(const Player & player, const Coordinate & coor)
{
char symbol = player.getSymbol();
m_Board[coor.m_Row][coor.m_Column] = symbol;
}