im trying to pass an object to an inherited clas by a construcotr however im facing some probelms can someone tell me what im doing wrong. im HAving Cboard my board and i need to pass it to the object Cpawn here under is my code:
main
Code:
#include<iostream>#include "Cboard.h"
#include "Cpawn.h"
#include "Cpiece.h"
void main(){
char location[50];
char piece;
int oldrow=0,oldcolumn=0,newrow=0,newcolumn=0,check =0,end=0;
Cboard myboard;
Cpawn mypawn(&myboard);
Cpiece *piecer = &mypawn;
do{
std::cout<<std::endl;
(myboard).printboard();
std::cout<<std::endl;
std::cout<<"please enter location";
std::cin>>location;
check =(myboard).validateuserinput(location,&newcolumn,&newrow,&oldrow,&oldcolumn);
//piece = (*myboard).board[]
if(check==0){
std::cout<<"correct";
if((*piecer).movepiece(&newcolumn, &newrow,&oldrow,&oldcolumn)==1){
(myboard).moveer(&newrow,&newcolumn,&oldrow,&oldcolumn);
(myboard).move();
}
}
else{
std::cout<<"error";
}
end++;
}while(end!=8);
}
Cpawn.h
Code:
#pragma once#include "Cpiece.h"
class Cpawn:public Cpiece
{
public:
virtual char getcolor();
virtual char setcolor(char colour);
virtual char getpiece();
virtual int movepiece(int *newcolumn, int *newrow, int *oldrow,int *oldcolumn);
char col;
Cboard *mboard;
Cpawn(Cboard *board);
};
Cpawn.cpp
Code:
#include <iostream>#include "Cpawn.h"
#include "Cpiece.h"
#include"Cboard.h"
char Cpawn::getpiece(){
return 'p';
}
Cpawn::Cpawn(Cboard *board){
mboard = board;
}
char Cpawn::setcolor(char colour){
col = colour;
return col;
}
char Cpawn::getcolor(){
return col;
}
int Cpawn::movepiece(int *newcolumn, int *newrow,int *oldcolumn,int *oldrow){
int correct =0;
int old ,old1;
char piece;
old =*oldrow;
old1 = *oldcolumn;
piece= mboard->board[1][1]->getcolor;
if(*oldrow == *newrow && *oldcolumn-1 == * newcolumn||*oldrow == *newrow && *oldcolumn+1 == * newcolumn){
correct =1;
}
return correct ;
}
Cpiece.h
Code:
#pragma once
class Cpiece
{
protected:
public:
virtual char getcolor() =0;
virtual char setcolor(char colour)=0;
virtual char getpiece()=0;
virtual int movepiece(int *newcolumn, int *newrow, int *oldrow,int*oldcolumn)=0;
char getcolumn();
char getrow();
//Cboard bord;
void setvalue(int oldcolumn,int oldrow);
//Cpiece (void);
//Cpiece(Cboard board);
int row,column;
//~Cpiece(void);
};
cpiece.cpp
Code:
#include "Cpiece.h"
/*Cpiece::Cpiece(void)
{
}
/*Cpiece::Cpiece(Cboard myboard){
bord = myboard;
}*/
/*Cpiece::~Cpiece(void)
{
}*/
void Cpiece::setvalue(int oldcolumn,int oldrow){
row =oldrow ;
column = oldcolumn;
}
char Cpiece::getcolumn(){
return column;
}
char Cpiece::getrow(){
return row;
}