error:no matching fucntion for call to 'Square::Square(SquareColor&,Location*)'
error:no matching fucntion for call to 'Square::Square(SquareColor&,Location*)'
我正在尝试用 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));
我正在尝试用 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));