I'm trying to call initCapture() that's declared pure virtual in LexContext. I'm trying to call it indirectly in ArduinoLexContext by way of StaticLexContext which overrides it.
I get
LexContext.hpp:316:25: error: there are no arguments to 'initCapture' that depend on a template parameter, so a declaration of 'initCapture' must be available [-fpermissive]
Here's the code. I've omitted most of LexContext since it isn't relevant here. I've been at this all morning and I know the answer is staring me right in the face but I need another set of eyes on this.
Thanks in advance.
#include <cstdint>
#include <ctype.h>
#include <stdlib.h>
namespace lex {
// represents a cursor and capture buffer over an input source
class LexContext {
int16_t _current;
unsigned long int _line;
unsigned long int _column;
unsigned long long _position;
protected:
// reads a character from the underlying device
// read() should return EndOfInput if no more data is available,
// and Closed if the underlying source has been closed, where
// applicable
virtual int16_t read()=0;
// called to initialize the capture buffer
virtual void initCapture()=0;
public:
...
};
// represents a LexContext with a fixed size buffer
template<const size_t S> class StaticLexContext : virtual public LexContext {
char _capture[S];
size_t _captureCount;
protected:
// initializes the capture buffer
void initCapture() override {
*_capture=0;
_captureCount=0;
}
public:
StaticLexContext() {
}
// the capacity of the capture buffer (not including the trailing NULL)
size_t captureCapacity() override { return S-1; }
// the count of characters in the capture buffer
size_t captureCount() const override {return _captureCount;}
// returns a pointer to the capture buffer
char* captureBuffer() override {return _capture;}
// clears the capture buffer
void clearCapture() override {
_captureCount = 0;
*_capture=0;
}
// captures the character under the cursor if any
// returns true if a character was captured.
bool capture() override {
if (Closed!=current() && EndOfInput != current() && BeforeInput != current() && (S - 1) > _captureCount)
{
_capture[_captureCount++] = (uint8_t)current();
_capture[_captureCount] = 0;
return true;
}
return false;
}
};
#ifdef ARDUINO
// represents a fixed length LexContext for the Arduino built on the Arduino SDK's Stream class
template<const size_t S> class ArduinoLexContext : public StaticLexContext<S> {
Stream* _pstream;
protected:
// reads a character from the stream
int16_t read() override {
if(!_pstream)
return LexContext::Closed;
return _pstream->read();
}
public:
ArduinoLexContext() {
}
// initializes the lexcontext with a stream
bool begin(Stream& stream) {
_pstream = &stream;
initCapture(); // compile error!
return true;
}
};
#endif
}
Aucun commentaire:
Enregistrer un commentaire