-1

I have created a class that abstracts a SPI flash chip library called SerialFlash by creating an abstract class of Print.h. When I try to print to this by using the ArduinoJson library, I get an error:

src/FlashMemory.cpp:99:36: error: no matching function for call to 'ArduinoJson::JsonObject::printTo(<unresolved overloaded function type>)'
root.printTo(serialFlashPrint);
^

lib/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:34:10: note: size_t ArduinoJson::Internals::JsonPrintable<T>::printTo(Print&) const [with T = Ardu
inoJson::JsonObject; size_t = unsigned int]
size_t printTo(Print &print) const {
^
lib/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:34:10: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 
'Print&'

The file referenced in the error above is here: https://github.com/bblanchon/ArduinoJson/blob/master/include/ArduinoJson/Internals/JsonPrintable.hpp

This is the header file for the class:

#include <Arduino.h>
#include <SerialFlash.h>
#include "Print.h"

#ifndef _SerialFlashPrint_h_
#define _SerialFlashPrint_h_

class SerialFlashPrint : public Print {
  public:
    SerialFlashPrint(SerialFlashFile *file);

    virtual size_t write(uint8_t);
    virtual size_t write(const uint8_t *buffer, size_t size);

  private:
    char buf[1];
    uint16_t _current_byte;
    SerialFlashFile * _file;
};

#endif

And the cpp file:

#include "serialFlashPrint.h"

SerialFlashPrint::SerialFlashPrint(SerialFlashFile * file) : Print() {
  this->_file = file;
  this->_current_byte = 0;
}

size_t SerialFlashPrint::write(uint8_t c) {
  if(_current_byte == 0){
    _file->erase();
    _file->seek(0);
  }
  sprintf(buf, "%c", c);
  _file->write(buf, 1);
  _current_byte++;
  return 0;
}

size_t SerialFlashPrint::write(const uint8_t *buffer, size_t size){
  _file->erase();
  _file->seek(0);
  _file->write(buffer, size);
  _file->write(NULL, 1);
  return 0;
};

Generally, you use print function as: the root.printTo(Serial). This code is based upon an abstraction (which I got to work previously) called Chunked output that can be seen here: https://github.com/bblanchon/ArduinoJson/wiki/Bag-of-Tricks

Does anyone have any clues for me to figure out why I am getting <unresolved overloaded function type> instead of Print&?

cosmikwolf
  • 399
  • 7
  • 15

1 Answers1

0

<unresolved overloaded function type> means that the compiler found a function with several overloads and doesn't know which one to use.

You most likely have several serialFlashPrint() in your code or libraries.

If not, then you may have triggered the Most vexing parse:

SerialFlashPrint serialFlashPrint;   // <- creates an instance of SerialFlashPrint  
SerialFlashPrint serialFlashPrint(); // <- declares a function returning a SerialFlashPrint 
Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81