Say I have an array of pointers to an abstract class:
Piece *pieces[2]; // where piece is an abstract class
And I have two classes that extend Piece
called King
and Queen
. I assign a King
to a spot in pieces
and Queen
to another spot:
pieces[0] = new King();
pieces[1] = new Queen();
If I haven't overloaded the assignment operator, does slicing occur? Or does pieces[0]
is an instance of King
and pieces[1]
is an instance of Queen
? What is going on in that array (if this was C++)?
EDIT: See a full example of the code in question here.