Error Builder from abstract class undefined reference to `vtable for

Possible duplicate:
Undefined symbols "vtable for ..." and "typeinfo for ..."?
C ++ Undefined Link to vtable and inheritance

I have a problem with a small project required from my university. This is a simple chess game project.

I have an unclear error Undefined reference to `vtable for XXX when I define an inherited class from an abstract ... This is the code

Pieces.h

class Pieces { public: Pieces(char color) : pieceColor(color) {} virtual ~Pieces() {} virtual char getPieceType() = 0; char getColor() { return pieceColor; } virtual bool isLegalMove(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]) = 0; private: virtual bool areSquaresLegal(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]) = 0; char pieceColor; }; 

and this is an example of an inherited class, i.e. a pawn

Pawn.h

 #include "Pieces.h" class Pawn: public Pieces { public: Pawn(char color) : Pieces(color) {} ~Pawn(); private: virtual char getPieceType() { return 'P'; } bool areSquaresLegal(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]); bool isLegalMove(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]); }; 

The last two methods are implemented in the .cpp file. Obviously, every other class is like a pawn.

When I try to compile, the builder gives me: undefined reference to vtable for Pawn`` with reference to the line in which the constructor:

 Pawn(char color) : Pieces(color) {} 

Where am I going wrong?

+4
source share
1 answer

You say that you have implemented the last two member functions. I assume that you did not implement the destructor that you declared, but not defined in the class.

If you need a non-trivial destructor for a class, make sure you implement it. If not, delete his ad.

In general, this error means that you declared an unclean virtual function and forgot to implement it; some popular compilers put polymorphic class metadata in the same translation unit as the first unclean, non-unit member function, which in this case is a destructor. If you see an error for a class that should be abstract, it usually means that you forgot to declare some of your virtual functions clean.

+6
source

Source: https://habr.com/ru/post/1434174/


All Articles