不能将字段'Executive :: history'声明为抽象类型

时间:2017-09-24 22:28:04

标签: c++ compiler-errors abstract-class

我已经阅读了一些关于这个错误的帖子,并且已经看到流行的问题是对象类中有纯虚方法,但我没有任何我能看到的。 错误消息为executive.h:13:44: error: invalid new-expression of abstract class type ‘List<std::__cxx11::basic_string<char> >’

这是executive.h

private:
    string command="";
    List<string>* history = new List<string>();
    int currentPosition=0;

public:
    Executive(string filename);
    ~Executive();
    void navigateTo(string url);

    void forward();

    void back();

    string current() const;

    void copyCurrentHistory(List<string>& destination);

    void printHistory(); 

List.h

template <class T>
class List: public ListInterface<T>{    
private:
    int length;
    Node<T>* head= nullptr;

public:
    List();
    ~List();
    bool isEmpty() const;

    int getLength() const;

    void insert(int newPosition, const T& newEntry) ;

    void remove(int position) ;

    void clear();

    T getEntry(int position);

    void setEntry(int position, const T& newEntry);

    Node<T>* getNode(int postion);

我的类是纯虚方法listInterface.h

template<class T>
class ListInterface
{    
public:


     virtual ~ListInterface() {}
     virtual bool isEmpty() const = 0;
     virtual int getLength() const = 0;
     virtual void insert(int newPosition, const T& newEntry) = 0;
     virtual void remove(int position) = 0;
     virtual void clear() = 0;
     virtual T getEntry(int position) const = 0;
     virtual void setEntry(int position, const T& newEntry) = 0;

我也从我的编译器那里得到一条说明但是我没有做,因为它说的是我的班级名称所在的行。

list.h:11:7: note:   because the following virtual functions are pure within ‘List<std::__cxx11::basic_string<char> >’:
 class List: public ListInterface<T>{

1 个答案:

答案 0 :(得分:0)

T getEntry(int position);不是virtual T getEntry(int position) const = 0;的实现。将const添加到方法的签名。

相关问题