//Here's my problem... I have a class Piece which is my base class for a checkers game.
//I have two derived classes Pawn and King. A couple of functions in the base class
//are virtual functions. Now from my understanding i should be able to do this:
/*
Piece *Board[8][8];
Board[0][0] = new Pawn();
Board[1][1] = new King();
//When I do this i get the error:
//d:\programming\checkers\checkers.cpp(210) : error C2243: 'type cast' : conversion from 'class Pawn *' to 'class Piece *' exists, but is inaccessible
//d:\programming\checkers\checkers.cpp(211) : error C2243: 'type cast' : conversion from 'class King *' to 'class Piece *' exists, but is inaccessible
//Any ideas on this one? Here are my class declarations, their in 3 seperate files.
class Piece {
protected:
Point pos;
TEAM myTeam;
int numPossible;
LinkedList<Point> possible;
public:
Piece(void) { numPossible=0; };
Piece(Point p, TEAM t) { myTeam=t; pos=p; numPossible=0; };
Piece(int x, int y, TEAM t) { myTeam=t; pos.x=x; pos.y=y; numPossible=0; };
virtual ~Piece() {;};
virtual Piece* Clone() { return(new Piece(*this)); };
void setTeam(TEAM t) { myTeam = t; };
TEAM getTeam(void) { return(myTeam); };
void setCoord(Point p) { pos=p; };
void setCoord(int x, int y) { pos.x=x; pos.y=y; };
void getCoord(Point &p) { p=pos; };
void getCoord(int &x, int &y) { x=pos.x; y=pos.y; };
void clearPossibleMoves(void);
virtual void fillPossibleMoves(void) {;}
private:
virtual void checkJump(void) {;}
};
class Pawn : Piece {
public:
Pawn() : Piece() {};
Pawn(Point p, TEAM t) : Piece(p, t) {};
Pawn(int x, int y, TEAM t): Piece(x, y, t) {};
virtual ~Pawn() {;};
virtual Piece* Clone() { return(new Pawn(*this)); };
virtual void fillPossibleMoves(TEAM board[8][8], int ydir);
private:
virtual void checkJump(TEAM board[8][8], Point p, int ydir);
};
class King : Piece {
public:
King : Piece() {};
King(Point p, TEAM t) : Piece(p, t) {};
King(int x, int y, TEAM t) : Piece(x, y, t) {};
virtual ~King() {;};
virtual Piece* Clone() { return(new King(*this)); };
virtual void fillPossibleMoves(TEAM board[8][8]);
private:
virtual void checkJump(TEAM board[8][8], Point p, int ydir);
};
Thanks in advance for your help....
Edited by - 40 Thieves on 8/19/00 10:30:22 AM
Problems with Virtual Inheritance
-40
simple mistake. You need to declare what type of inheritance you want.
class king : public piece
class pawn : public piece
you could also declare it as private or protected. It usually depends on the functionnality of your object. In your case you want public inheritance.
public --> the public and protected member are accessible by the derived class
protected --> the public and protected member are accessible by the class, but an outside program//class cannot access the public method of the base class
private --> Only the public member are accessible to the derived class and an outside program//class cannot get access to the public method of the base class
class king : public piece
class pawn : public piece
you could also declare it as private or protected. It usually depends on the functionnality of your object. In your case you want public inheritance.
public --> the public and protected member are accessible by the derived class
protected --> the public and protected member are accessible by the class, but an outside program//class cannot access the public method of the base class
private --> Only the public member are accessible to the derived class and an outside program//class cannot get access to the public method of the base class
I was up till 6am stuck on this problem for 2 hours and finally gave up and went to bed.... I just have one thing to say....
(to the music of Wind Beneath My Wings):
"
Did you ever know that you''re my heeeeeeeerooooooo....
You''re everything I wish I could beeeeeeeeeeeeee....
I can code faster than an eagle......
cause I''ve got you guys here on GD....
"
Thanks alot guys
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
(to the music of Wind Beneath My Wings):
"
Did you ever know that you''re my heeeeeeeerooooooo....
You''re everything I wish I could beeeeeeeeeeeeee....
I can code faster than an eagle......
cause I''ve got you guys here on GD....
"
Thanks alot guys
40
www.databyss.com
www.omlettesoft.com
"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."
-40
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement