I'm currently converting a project from Java into C++. I'm using base classes as interface classes and I'm using derived classes as a subclass of the "interface" class. Right now, I'm having an issue regarding base and derived classes. Here's some of the code in the CPP file:
enum class State {
START, INTEGER, DECIMAL, END
};
class Edge {
private:
State currentState;
InputVerifier inputVerifier;
Action action;
State nextState;
public:
Edge(State _currentState, InputVerifier _inputVerifier, Action _action, State _nextState) {
currentState = _currentState;
inputVerifier = _inputVerifier;
action = _action;
nextState = _nextState;
}
};
Edge machine[1] = {
Edge(State::START, DigitInputVerifier(), ValueIsDigitAction(), State::INTEGER)
};
And some of the code in the header file:
class InputVerifier {
public:
virtual bool meetsCriteria(char c) = 0;
};
class Action {
public:
virtual InterimResult execute(InterimResult x, char c) = 0;
};
class ValueIsDigitAction: public virtual Action {
public:
InterimResult execute(InterimResult x, char c) override {
x.setV(c - '0');
return x;
}
};
class DigitInputVerifier: public virtual InputVerifier {
public:
bool meetsCriteria(char c) override {
if (c >= '0' && c <= '9') {
return true;
}
return false;
}
};
InterimResult is another class but that's not an issue. I've been trying to compile this but one of the errors I keep on getting is error: cannot declare parameter '_inputVerifier' to be of abstract type 'InputVerifier'. I've been trying to search this issue up but I'm not having much luck. I'm new to using classes in C++ so I'm trying to learn but I don't understand how to fix this error. If you could, could you explain what a pure virtual function is too? Any help would be greatly appreciated.