-1

我创建了一个类,它通过创建 Print.h 的抽象类来抽象一个名为 SerialFlash 的 SPI 闪存芯片库。当我尝试使用 ArduinoJson 库进行打印时,出现错误:

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&'

上面错误中引用的文件在这里:https ://github.com/bblanchon/ArduinoJson/blob/master/include/ArduinoJson/Internals/JsonPrintable.hpp

这是该类的头文件:

#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

和 cpp 文件:

#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;
};

通常,您将打印功能用作:root.printTo(Serial)。此代码基于称为块输出的抽象(我之前工作过),可以在此处看到:https ://github.com/bblanchon/ArduinoJson/wiki/Bag-of-Tricks

有没有人有任何线索让我弄清楚为什么我得到<unresolved overloaded function type>而不是 Print&?

4

1 回答 1

0

<unresolved overloaded function type>意味着编译器发现了一个具有多个重载的函数并且不知道该使用哪个。

您的代码或库中很可能有几个serialFlashPrint()

如果没有,那么您可能触发了最令人烦恼的解析

SerialFlashPrint serialFlashPrint;   // <- creates an instance of SerialFlashPrint  
SerialFlashPrint serialFlashPrint(); // <- declares a function returning a SerialFlashPrint 
于 2016-11-24T09:52:49.577 回答