initCapture()
LexContext
ArduinoLexContext
StaticLexContext<S>
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]
#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 }
The problem isn't the protected-ness. The problem is that ArduinoLexContext derives from a template class. The compiler sees initCapture(); and says, "Is this a member function derived from a base class? Or is it a global function? I'm going to assume it's a global function. Error: No global function called initCapture." (There might be a specialization template<> StaticLexContext<0> { /* doesn't derive from LexContext, no initCapture method */ }.) You need to help out the compiler and write this->initCapture() to say "The initCapture method is coming from my base class, trust me."
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)