그래서 조각 클래스를 보드 상에 표현해야하는데, 거기에서 상속받은 두 개의 다른 클래스를 가질 계획이다. 그러나 이렇게하는 데 많은 어려움을 겪었습니다. 지금까지 관련 코드가 있습니다.나는 상속을 엉망으로 만들고있다.
///
/// PIECE CLASS HERE
/// this is an abstract class from which Barrier and Pawn inherit.
class Piece
{
public:
Piece(Space* start);
sf::Shape m_Circle;
protected:
int m_X;
int m_Y;
int m_radius;
Space* CurrentSpace;
};
Piece::Piece(Space* start):
m_X(start->GetX()),
m_Y(start->GetY()),
m_radius(14),
CurrentSpace(start)
{}
///
/// BARRIER CLASS HERE
/// these are the white stones that block a player's path
class Barrier : public Piece
{
public:
Barrier(Space* initial);
void Move(Space* target, bool isCapturing);
};
Barrier::Barrier(Space* initial)
{
Piece(initial);
m_Circle = sf::Shape::Circle((float)m_X, (float)m_Y, (float)m_radius, sf::Color(255, 255, 255));
Move(initial);
}
void Barrier::Move(Space* target, bool isCapturing)
{
int xChange = abs(target->GetX() - m_X);
int yChange = abs(target->GetY() - m_Y);
m_Circle.Move((float)xChange, (float)yChange);
CurrentSpace.ToggleOccupied();
if(!isCapturing)
{
(*target).ToggleOccupied();
}
CurrentSpace = target;
}
나는 특히 내가 이해하지 못하는 오류의 하중을 받고 있어요 : C++에 새가되는
no matching function for call to Piece::Piece()
declaration of 'Piece initial' shadows a parameter
no matching function for call to 'Barrier::Move(Piece&)'
request for member 'ToggleOccupied' in '((Barrier*)this)->Barrier::<anonymous>.Piece::CurrentSpace', which is of non-class type 'Space*'|
, 나는이 모든 잘못 무슨 일이 일어나고 있는지 이해가 안 돼요. C++을 배웠던 책에서 찾은 코드와 비슷한 코드를 만들려고했지만 분명히 약간의 미묘한 점을 간과했습니다. 내가 호출하려고하는 모든 함수는 적절한 위치에있는 것처럼 보이며 프로토 타입과 동일한 값으로 정의합니다.
두 번째 오류는 클래스 중괄호 안의'Piece (initial)'가 지역 변수를 선언 한 다음'Move (initial)'가'Piece' lvalue를'Barrier :: 이동 '기능. –