so i am making a chess board .
non gui , just the logic.
I have a mother class called piece , and the sub classes (rook ,queen...)which inherit from it.
the board is an 8x8 vector of type piece. in the mother class i have a virtual function called checkLegality which is implemented differently in all classes . the problem i have is that , when i try to call check legality , the virtual version gets called
here is the code.
piece class (mother)
well in the case i have , it should contain a rook, and when i call potentialPieces[0]->pType , it gives the value of a rook . but piece::checkLegality is called anyway .
virtualbool checkLegality (int x , int y , std::vector <std::vector <piece>> board ) {}
This concerns me. The board variable here can never hold any type other than piece. If newMove is operating on the same variable type, it will never deal with anything other than a piece, regardless of the type indicated by the pType member (and, I have to ask, if you're keeping track of the type already what's the point in the virtual function?)
Please address my last post. You seem to have multiple variables with the same name (board) and different types and it's rather confusing.
line 16 in the last snippet in the OP would seem to result in object slicing (if, indeed, there were any object other than a piece pointed to by the elements in potentialPieces.)
You shouldn't mix relying on inheritance mechanisms and using member data directly. It's a contradiction.
Anyway, you still haven't shown where those pointers are created. You don't seem to get that that is the key to determining how a virtual function call is determined.