I'm making a checkers game in C++.
I have a class Board with a locationSquareMap map object.
#ifndef BOARD_H
#define BOARD_H
#include "Square.h"
#include <vector>
#include "Man.h"
#include <map>
typedef std::vector<Square*> Column;
class Board
{
const int BOARD_SIZE = 8;
std::vector<Column> squares;
std::map<Location, Square*> locationSquareMap;
public:
Board();
~Board();
//Board(Board& board);
void printBoard();
};
#endif
When I do nothing on locationSquareMap program compiles successfully.
#include "Board.h"
Board::Board()
{
//locationSquareMap
for (int row = 0; row < BOARD_SIZE; row++)
{
squares.push_back(Column());
for (int column = 0; column < BOARD_SIZE; column++)
{
Location currentLocation(File(column), row);
SquareColor currentSquareColor = SquareColor::WHITE;
if ((column + row) % 2 == 0)
{
currentSquareColor = SquareColor::BLACK;
}
Square* currentSquare = new Square(currentLocation, currentSquareColor);
//locationSquareMap.insert(std::make_pair(currentSquare->getLocation(), currentSquare));
//works fine without refering to the locationSquareMap
squares.at(row).push_back(currentSquare);
}
}
}
Board::~Board()
{
}
void Board::printBoard()
{
for (int i = squares.size() - 1; i != -1; i--)
{
for (int g = squares.at(i).size() - 1; g != -1; g--)
{
std::cout << *(squares.at(i).at(g)) << std::endl;
}
}
std::cout << " ";
for (int i = 0; i < BOARD_SIZE; i++)
{
switch (File(i))
{
case File::A : std::cout << "A "; break;
case File::B : std::cout << "B "; break;
case File::C : std::cout << "C "; break;
case File::D : std::cout << "D "; break;
case File::E : std::cout << "E "; break;
case File::F : std::cout << "F "; break;
case File::G : std::cout << "G "; break;
case File::H : std::cout << "H "; break;
default: std::cout << " "; break;
}
}
std::cout << std::endl << std::endl;
for (int i = squares.size() - 1; i != -1; i--)
{
std::cout << i << " ";
//for (int g = squares.at(i).size() - 1; g != -1; g--)
for(int g = 0; g < squares.at(i).size(); g++)
{
if (squares.at(i).at(g)->getColor() == SquareColor::BLACK)
{
std::cout << "B ";
}
else
{
std::cout << "W ";
}
}
std::cout << std::endl;
}
}
But when I try to insert the values into the map I have the C2676 error in the completely another place.
for(int g = 0; g < squares.at(i).size(); g++)
{
if (squares.at(i).at(g)->getColor() == SquareColor::BLACK)
{
std::cout << "B ";
}
else
{
std::cout << "W ";
}
}
std::cout << std::endl;
That's very strange because map does nothing with this loop.
Compilation error is following:
Error C2676 binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator Checkers3.0 C:\VisualStudio2019\VC\Tools\MSVC\14.28.29333\include\xstddef 127