我正试图用C++制作一个国际象棋游戏,但我遇到了一个错误,无法解决
其中错误为:
for(auto file : all_E)
{
Square newSquare= new Square(currentColor, new Location(file,i));
boardSquares[i][column]=newSquare;
}
这些是Square
和Location
类
class Square {
SquareColor squareColor;
Location location;
bool isOcuppied;
public:
Square();
Square(SquareColor sqCol, Location loc );
void reset();
bool isOccupied();
void setOccupied(bool occupied);
SquareColor getSqCol();
Location getLoc();
char* toString();
};
class Location {
File file;
int rankk;
public:
Location();
Location(File _file, int _rankk);
File getFile();
int getRank();
};
我读到这个错误,并尝试添加默认的构造函数Square()
和Location()
,但没有成功。
您构造的是指针(Location*
(,而不是对象(Location
(,这就是构造函数不匹配的原因。
移除new
:
Square newSquare = Square(currentColor, Location(file,i));