tags:

views:

51

answers:

1

I have the following class:

#include <string>
#include <stack>
#include <queue>
#include "map.h"

using namespace std;

#ifndef CONTAINER_H_
#define CONTAINER_H_

struct PathContainer {
    int x, y;
    string path;
};

class Container {
public:
    virtual void AddTile(string, FloorTile *) = 0;
    virtual void ClearContainer() = 0;
    virtual PathContainer *NextTile() = 0;
};

class StackImpl : public Container {
private:
    stack<PathContainer> cntr;
public:
    StackImpl();
    void AddTile(string, NeighborTile *);
    void ClearContainer();
    PathContainer *NextTile();
};

class QueueImpl : public Container {
private:
    queue<PathContainer> cntr;
public:
    QueueImpl();
    void AddTile(string, NeighborTile *);
    void ClearContainer();
    PathContainer *NextTile();
};
#endif

When I try creating StackImpl or QueueImpl object like so:

Container *cntr;
cntr = new StackImpl();

or

Container *cntr;
cntr = new QueueImpl();

I get the following error at compile:

escape.cpp: In function ‘int main(int, char**)’: escape.cpp:26: error: cannot allocate an object of abstract type ‘StackImpl’ container.h:23: note: because the following virtual functions are pure within ‘StackImpl’: container.h:18: note: virtual void Container::AddTile(std::string, FloorTile*)

Any ideas?

+5  A: 

typeid(NeighborTile *) != typeid(FloorTile *). The signatures differ, so they don't count as "the same" method even if NeighborTile inherits from FloorTile.

Jonathan Grynspan