Bear with me, I'm relatively new at C++.
Here is my project. I want to essentially create a simple game of chess.
I've got a base class gamePiece, which I'm thinking will eventually become an abstract class ( but right now it isn't)
The base class gamePiece has a bunch of data members in it: colorOfPiece, rankOfPiece, fileOfPiece, etc. It also has a function, void displayPieceInfo() which simply displays all of these values on the console via cout.
I am planning on having a number of derived classes from this one. Right now I have a "rook" subclass.
I want to add various types of pieces in a single vector, so I can later traverse it with an iterator.
Here is the problem I am running into.
vector<gamePiece> vectorOfAllGamePieces;
vector<gamePiece>::iterator itGamePieces;
I push_back a Rook into the vector as the first element. All the constructors look like they are running fine, initializing the variables. Yet when I try to run the display function on the first element, the strings are empty/unitialized.
itGamePieces=vectorOfAllGamePieces.begin();
itGamePieces->displayPieceInfo();
If I were to push in a generic gamePiece into the vector instead, everything would display properly.
Am I allowed to even have a vector like this with mixed types of objects -- for example, an object of a derived class, an object of the parent class, an object of a second class derived from the same parent
And if so, why do you suppose the values of the data members aren't showing up properly, even after I have set them in the constructor?