c++ - How to assign a subclass to an abstract class pointer in a function? -


void player::move(board &board, solver &solver){    position* best = solver.find_best_move(&board);    cout<<"score: "<<best->get_score()<<endl;    cout<<"board: ";    best->get_board()->print_board();    board = *(best->get_board());    board * b(best->get_board());    cout<<"test: ";    b->print_board();    board = *b;   } 

i'm trying make actual board reference equal new board after calling function. board abstract class , get_board() returning pointer board subclass of board has attribute. however,after move function called, board same board before call move. possible assign subclass pointer abstract super class, while modifying actual value? issue of slicing seems occurring.

i use board* pointer instead of board& reference, since subclass involved:

void player::move(board **board, solver &solver) {     position *best = solver.find_best_move(*board);     cout << "score: " << best->get_score() << endl;     *board = best->get_board();     cout << "board: ";     (*board)->print_board();  }   player p; solver solver; board *b = ...; p.move(&b, solver); 

or:

void player::move(board* &board, solver &solver) {     position *best = solver.find_best_move(board);     cout << "score: " << best->get_score() << endl;     board = best->get_board();     cout << "board: ";     board->print_board();  }   player p; solver solver; board *b = ...; p.move(b, solver); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -