저는 체스 판을 프로그래밍하고 있으며, 기본 클래스 chesspiece (내 언어로는 schaakstuk)를 사용했으며 king, queen과 같은 모든 조각은 기본 클래스에서 파생되었습니다.생성자가 추상 클래스에서 객체를 만들 수 없습니다.
이제 객체를 만들고 객체로 배열을 채워서 게임을 시작하겠습니다. Visual Studio에서 다음 줄에 몇 가지 오류를 표시합니다.
bord[1][kolom] = new Schaakstuk(Schaakstuk::WIT);
bord[6][kolom] = new Pion(Schaakstuk::ZWART);
추상 클래스로는 만들 수 없습니다. 나는 오류를 보지 못했지만, 처음에는 파생 된 클래스에서 순수한 virutal 함수를 사용하고 있다고 생각했지만 실제로는 기본 클래스에서 순수 가상 함수 만 사용하고 있습니다.
생성자
for(int kolom = 0; kolom < SIZE; kolom++)
{
bord[1][kolom] = new Pion(Schaakstuk::WIT);
bord[6][kolom] = new Pion(Schaakstuk::ZWART);
}
Pion.h
#include "Schaakstuk.h"
#include "Exceptions.h"
#ifndef PION
#define PION
class Pion: public Schaakstuk
{
public:
Pion(void);
~Pion(void);
bool ZetIsLegaal(int rij1, int kolom1, int rij2, int kolom2) const;
void PrintStuk(void) const;
void GeefCor(int tabel [8][2], int rij, int kolom, int rij1, int kolom1) const;
bool IsPion(void) const { return true; };
private:
bool ControleerZet(int rij1, int kolom1, int rij2, int kolom2) const;
};
#endif
Schaakstuk.h는
#ifndef SCHAAKSTUK
#define SCHAAKSTUK
static const int SIZE1 = 8;
class Schaakstuk
{
public:
enum kleurType { WIT, ZWART };
Schaakstuk(kleurType kleur = WIT)
{
this->kleur = kleur;
};
virtual bool ZetIsLegaal(int rij1, int kolom1, int rij2, int kolom2) = 0;
virtual void PrintStuk(void) = 0;
virtual void GeefCor(int tabel [8][2], int rij, int kolom, int rij1, int kolom1) = 0;
kleurType GeefKleur(void) const { return kleur; };
virtual bool IsPion(void) = 0;
protected:
bool static NietOutOfBounds(int rij, int kolom);
private:
kleurType kleur;
};
#endif
코드 파일 내 보관함입니다. 누군가 나를 도울 수 있습니까?
이
는 오류입니다 : 여기및 전체 코드 단어는 '추상적'는 멀리주고있다
알 수없는 사용자의 보관 용 계정에서 RAR 파일을 다운로드하지 않는 것이 확실합니다. –
idecase.com에 테스트 케이스 게시. –
클래스 선언을 질문에 넣어주세요. 그러나 오류로 판단하면'Pion'에 순수 가상 함수가 있습니다. 사실이라면'Pion'의 새로운 인스턴스를 직접 만들 수 없으며 그 하위 클래스 중 하나만 모든 순수 가상을 구현하며 추상이 아닙니다. – birryree