Hi,
I believe the IDE has kind of a hiccup while deriving a class from Print or my libraries are all wrong. I wanted to override the size_t println(void) function to provide my own upon deriving from Print, but it says it is not. Am I using the Ice wrong?
I feel there is something wrong with my IDE or my IDE libraries but I do not know what. Also, the function flush() is properly overriden so I am confident on the coding.
I tried creating a new project and copy the text file by file, but the error remains.
Here follow my headers and implementation, and also the error at compilation. Please, run a search for "println(void)". I did not just paste that for the sake of completion and because they are exactly the same char by char.
Thanks!!!
SMSPrint class HEADER
#ifndef SMS_PRINT_H
#define SMS_PRINT_H
#include <Arduino.h>
#include <MKRGSM.h>
class SMSPrint : public Print {
public:
SMSPrint(GSM_SMS &sms, const char *recipient);
void setRecipient(const char *recipient);
size_t write(uint8_t byte) override;
size_t println(void) override;
void flush() override;
private:
void sendSMS(); // Function to actually send the SMS
GSM_SMS *sms;
String message;
const char *recipient;
const size_t maxMessageLength = 160; // SMS max length
};
#endif // SMS_PRINT_H
SMSPrint class IMPLEMENTATION
#include "SMSPrint.h"
/*
Each instance will use its own recipient.
If a second recipient is needed, a second instance is required.
*/
SMSPrint::SMSPrint(GSM_SMS &sms, const char *recipient)
: sms(&sms), recipient(recipient) {}
void SMSPrint::setRecipient(const char *recipient) {
this->recipient = recipient;
message = "";
}
size_t SMSPrint::write(uint8_t byte) {
message += (char)byte;
if (message.length() >= maxMessageLength) {
sendSMS();
}
return 1;
}
size_t SMSPrint::println(void) {
//write('\r'); // Optional carriage return
sendSMS();
return 1;
}
void SMSPrint::flush() {
if (message.length() > 0) {
sendSMS();
}
}
void SMSPrint::sendSMS() {
if (recipient != nullptr && sms != nullptr) {
sms->beginSMS(recipient);
sms->print(message);
sms->endSMS();
}
message = ""; // Clear buffer after sending the SMS
}
ERRORS AT COMPILATION
In file included from /Users/me/Documents/Arduino/ControlRiego_0_5_0/SMSPrint.cpp:1:0:
/Users/me/Documents/Arduino/ControlRiego_0_5_0/SMSPrint.h:12:10: error: 'size_t SMSPrint::println()' marked 'override', but does not override
size_t println(void) override;
^~~~~~~
PRINT CLASS HEADER showing the original identical function
/*
Copyright (c) 2016 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <inttypes.h>
#include <stdio.h> // for size_t
#include "String.h"
#include "Printable.h"
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
namespace arduino {
class Print
{
private:
int write_error;
size_t printNumber(unsigned long, uint8_t);
size_t printULLNumber(unsigned long long, uint8_t);
size_t printFloat(double, int);
protected:
void setWriteError(int err = 1) { write_error = err; }
public:
Print() : write_error(0) {}
int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }
virtual size_t write(uint8_t) = 0;
size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}
// default to zero, meaning "a single write may block"
// should be overridden by subclasses with buffering
virtual int availableForWrite() { return 0; }
size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);
size_t print(char);
size_t print(unsigned char, int = DEC);
size_t print(int, int = DEC);
size_t print(unsigned int, int = DEC);
size_t print(long, int = DEC);
size_t print(unsigned long, int = DEC);
size_t print(long long, int = DEC);
size_t print(unsigned long long, int = DEC);
size_t print(double, int = 2);
size_t print(const Printable&);
size_t println(const __FlashStringHelper *);
size_t println(const String &s);
size_t println(const char[]);
size_t println(char);
size_t println(unsigned char, int = DEC);
size_t println(int, int = DEC);
size_t println(unsigned int, int = DEC);
size_t println(long, int = DEC);
size_t println(unsigned long, int = DEC);
size_t println(long long, int = DEC);
size_t println(unsigned long long, int = DEC);
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
virtual void flush() { /* Empty implementation for backward compatibility */ }
};
}
using arduino::Print;