undefined reference to vtable

I am trying to create a blackjack simulation.
There are two Player subclasses (SimplePlayer and CountingPlayer), derived from an abstract base class Player.
One of the methods is shared between the two subclasses, so I am trying to implement it in the manner of 'bool Player::Method(struct x, struct &y)' before the subclass implementations in the source file so that the subclasses inherit it, but if I omit declarations of this method from the two subclasses, I get the error:
cannot declare variable ‘impl’ to be of abstract type ‘CountingPlayer’ because the subclass becomes abstract
But if I include the declaration ('bool Method(struct x, struct y)') in the subclass implementation, I get the 'undefined reference to vtable' error.

How do I make the method inheritable by the subclasses so each subclass doesn't repeat the same implementation?

I cannot modify my header file, but the pure virtual method declared there is public.
I cannot modify my header file


You are not allowed to? Please elaborate.
It is a class assignment; the header file is given and cannot be modified, I can only write the .C source file.

Here is the header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef __PLAYER_H_
#define __PLAYER_H_

#include "hand.h"


class Player {
    // A virtual base class, providing the player interface
 public:
    virtual int bet(unsigned int bankroll,
                    unsigned int minimum) = 0; 
    // REQUIRES: bankroll >= minimum
    // EFFECTS: returns the player's bet, between minimum and bankroll 
    // inclusive

    virtual bool draw(Card dealer,             // Dealer's "up card"
                      const Hand &player) = 0; // Player's current hand
    // EFFECTS: returns true if the player wishes to be dealt another
    // card, false otherwise.

    virtual void expose(Card c) = 0;
    // EFFECTS: allows the player to "see" the newly-exposed card c.
    // For example, each card that is dealt "face up" is expose()d.
    // Likewise, if the dealer must show his "hole card", it is also
    // expose()d.  Note: not all cards dealt are expose()d---if the
    // player goes over 21 or is dealt a natural 21, the dealer need
    // not expose his hole card.

    virtual void shuffled() = 0;
    // EFFECTS: tells the player that the deck has been re-shuffled.

    virtual ~Player() { }
    // Note: this is here only to suppress a compiler warning.
    //       Destructors are not needed for this project.
};

extern Player *get_Simple();
// EFFECTS: returns a pointer to a "simple player", as defined by the
// project specification

extern Player *get_Counting();
// EFFECTS: returns a pointer to a "counting player", as defined by
// the project specification.

#endif /* __PLAYER_H__ */ 
the draw function is the method I am referring to, since both player types have identical behaviors for it.
Are you limited to the two subclasses only in the hierarchy? Meaning, could you subclass your abstract class with a 'concrete Player' class, implement methods that have same behavior for the other two subclasses then derive you two subclasses from the concrete class?
Topic archived. No new replies allowed.