このエラーについての他の記事を読んで、よくある問題はオブジェクトクラスに純粋な仮想メソッドがあるのですが、私は見えます。 エラーメッセージはこれがexecutive.hフィールド 'Executive :: history'を抽象型に宣言することはできません
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
あるクラスであるexecutive.h:13:44: error: invalid new-expression of abstract class type ‘List<std::__cxx11::basic_string<char> >’
です
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;
また、私のコンパイラからt彼が私のクラス名がどこにあるかということを言っているので、私はそれ以来行っていません。
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つずつ比較すると、一致しないメソッドが1つしか見つからないことがあります。あなたの宿題は 'override'キーワードの使い方を学ぶことです。これは、この共通のエラーをはるかに明白な方法で捕捉します。 –