私はチェス盤をプログラミングしています。私は基本クラス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
コードファイルと私のDropboxです。誰か助けてくれますか?
これはエラーです:
、ここでは完全なコードは
未知のユーザーのDropboxからRARファイルをダウンロードしていないと確信しています。 –
idecase.comにテストケースを投稿してください。 –
あなたのクラス宣言をあなたの質問に入れてください。しかし、あなたのエラーから判断すると、 'Pion'には純粋な仮想関数があります。本当に' Pion'の新しいインスタンスを直接作成することはできません。すべての純粋な仮想を実装し、抽象的ではありません。 – birryree