Problem with abstract base classes

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
class mob
{
protected:
    condition monster_condition;
public:
    int health;
    virtual void pass_turn() =0;
    void set_condition(condition set){monster_condition = set;}
};

class player : public mob
{
private:
    condition well_being;
public:
    inventory* Inv;
    void set_condition(condition set){well_being = set;}
    condition get_condition(){return well_being;}
    player()
    {
        Inv = new inventory;
        health = 200;
    }
    ~player() {delete Inv;}
    void pass_turn(mob&);
}me;


It's saying player's an abstract base class. In another header file, I give a definition to the pass_turn(mob&) method. So shouldn't polymorphic behaviour occur and player won't be an abstract base class? I'm probably being crazy here.
Last edited on
That depends on if the file containing the definition of "pass_turn(&mob)" is properly linked to this one. Can we see the include of this file and possibly the header containing the definition of "pass_turn(&mob)"?
First of all all members including functions shall be declared in the class definition So it is not clear where you gave the definition of pass_turn. I do not see it declaration in class player. Moreover in base class the function with the same name declared without any parameters. So in any case you defined another overloaded function.
Thus the compiler issues the error correctly.
Last edited on
Alright, thanks, got it!
Topic archived. No new replies allowed.