简体   繁体   English

没有匹配的函数无法调用未解析的重载函数类型

[英]no matching function for call unresolved overloaded function type

First I'm a newbie to C++ so my question might be already answered somewhere but I couldn't find a straightforward answer to it. 首先,我是C ++的新手,因此我的问题可能已经在某个地方得到解答,但是我找不到直接的答案。 I'm creating a simple library for my hardware. 我正在为我的硬件创建一个简单的库。 I'm using a Scheduler library which is working fine on Arduino IDE ( here is the example), but when I compile the code with my own IDE (Atom+PlatformIO) this error comes up: 我正在使用在Arduino IDE上运行良好的Scheduler库( 是示例),但是当我使用自己的IDE(Atom + PlatformIO)编译代码时,会出现以下错误:

lib\SRF08\SRF08.cpp:43:30: error: no matching function for call to 'SchedulerClass::startLoop(<unresolved overloaded functi
on type>)'

I removed some of the codes but if you need the rest I can put it. 我删除了一些代码,但是如果您需要其余代码,我可以放它。

SRF08.h SRF08.h

#ifndef SRF08_h
#define SRF08_h

#include "Arduino.h"

class SRF08
{
public:
    //main constructor
    SRF08(uint8_t address=address_1);
    // init the sensor
    void begin(void);

    //change sensor address from oldAddress to newAddress
    void changeAddress(uint16_t oldAddress, uint16_t newAddress);
    // scan for a single sensor address
    int8_t scanner(void);
    // scan for multiple sensors and return the table of addresses
    struct table_value scan_all(void);
    uint16_t output_value;
    void read(void);
private:
    // the main I2C address of Sensor
    uint16_t _address;
    //read sansor value base on centimiter
};
#endif

SRF08.cpp SRF08.cpp

#include "Wire.h"
#include "SRF08.h"
// Include Scheduler since we want to manage multiple tasks.
#include "Scheduler.h"

SRF08::SRF08(uint8_t address)
{
    //main constructor, address is the sensor address if u dont know it try scanner first
    //address must be an integer number between 1 to 9
    if (address == 1) _address = address_1;
     else _address = address_1;

}

void SRF08::begin(){
    //initilize I2C
    Wire.begin();
    output_value = 0;
    Scheduler.startLoop(SRF08::read);  //here is my error
}



void SRF08::read(){
    int reading = 0;
    // step 1: instruct sensor to read echoes
    Wire.beginTransmission(_address); // transmit to device #112 (0x70)
    // the address specified in the datasheet is 224 (0xE0)
    // but i2c adressing uses the high 7 bits so it's 112
    Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)
    Wire.write(byte(0x51));      // command sensor to measure in "inches" (0x50)
    // use 0x51 for centimeters
    // use 0x52 for ping microseconds
    Wire.endTransmission();      // stop transmitting

    // step 2: wait for readings to happen
    delay(70);                   // datasheet suggests at least 65 milliseconds

    // step 3: instruct sensor to return a particular echo reading
    Wire.beginTransmission(_address); // transmit to device #112
    Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
    Wire.endTransmission();      // stop transmitting

    // step 4: request reading from sensor
    Wire.requestFrom(_address, 2);    // request 2 bytes from slave device #112

    // step 5: receive reading from sensor
    if (2 <= Wire.available()) { // if two bytes were received
        reading = Wire.read();  // receive high byte (overwrites previous reading)
        reading = reading << 8;    // shift high byte to be high 8 bits
        reading |= Wire.read(); // receive low byte as lower 8 bits
        output_value = reading;   // print the reading
    }
    //yield();
}

Scheduler.h 调度程序

#ifndef _SCHEDULER_H_
#define _SCHEDULER_H_

#include <Arduino.h>

extern "C" {
    typedef void (*SchedulerTask)(void);
    typedef void (*SchedulerParametricTask)(void *);
}

class SchedulerClass {
public:
    SchedulerClass();
    static void startLoop(SchedulerTask task, uint32_t stackSize = 1024);
    static void start(SchedulerTask task, uint32_t stackSize = 1024);
    static void start(SchedulerParametricTask task, void *data, uint32_t stackSize = 1024);

    static void yield() { ::yield(); };
};

extern SchedulerClass Scheduler;

#endif

Scheduler.cpp Scheduler.cpp

#include "Scheduler.h"

extern "C" {

#define NUM_REGS 10 // r4-r11, sp, pc

typedef struct CoopTask {
    uint32_t regs[NUM_REGS];
    void* stackPtr;
    struct CoopTask* next;
    struct CoopTask* prev;
} CoopTask;

static CoopTask *cur = 0;
...
void yield(void) {
    coopDoYield(cur);
}

}; // extern "C"

SchedulerClass::SchedulerClass() {
    coopInit();
}

static void startLoopHelper(void *taskData) {
    SchedulerTask task = reinterpret_cast<SchedulerTask>(taskData);
    while (true)
        task();
}

void SchedulerClass::startLoop(SchedulerTask task, uint32_t stackSize) {
    coopSpawn(startLoopHelper, reinterpret_cast<void *>(task), stackSize);
}

static void startTaskHelper(void *taskData) {
    SchedulerTask task = reinterpret_cast<SchedulerTask>(taskData);
    task();
}

void SchedulerClass::start(SchedulerTask task, uint32_t stackSize) {
    coopSpawn(startTaskHelper, reinterpret_cast<void *>(task), stackSize);
}

void SchedulerClass::start(SchedulerParametricTask task, void *taskData, uint32_t stackSize) {
    coopSpawn(task, taskData, stackSize);
}

SchedulerClass Scheduler;

Thanks to @Someprogrammerdude to help. 感谢@Someprogrammerdude的帮助。 I needed to declare the read function as static. 我需要将read函数声明为静态。

SRF08.h SRF08.h

#ifndef SRF08_h
#define SRF08_h

#include "Arduino.h"

class SRF08
{
public:
    //main constructor
    SRF08(uint8_t address=address_1);
    // init the sensor
    void begin(void);

    //change sensor address from oldAddress to newAddress
    void changeAddress(uint16_t oldAddress, uint16_t newAddress);
    // scan for a single sensor address
    int8_t scanner(void);
    // scan for multiple sensors and return the table of addresses
    struct table_value scan_all(void);
    static uint16_t output_value;
    static void read(void);
    static uint16_t static_address;

private:
    // the main I2C address of Sensor
    uint16_t _address;
    //read sansor value base on centimiter
};
#endif

SRF08.cpp SRF08.cpp

#include "Wire.h"
#include "SRF08.h"
// Include Scheduler since we want to manage multiple tasks.
#include "Scheduler.h"

//initilize static members

uint16_t SRF08::output_value;
uint16_t SRF08::static_address;

SRF08::SRF08(uint8_t address)
{
    //main constructor, address is the sensor address if u dont know it try scanner first
    //address must be an integer number between 1 to 9
    if (address == 1) _address = address_1;
    else _address = address_1;
    static_address = _address;
    //begin();
}

void SRF08::begin(){
    //initilize I2C
    Wire.begin();
    output_value = 0;
    Scheduler.startLoop(read);  //here is my error
}


void SRF08::read(){
    int reading = 0;
    // step 1: instruct sensor to read echoes
    Wire.beginTransmission(static_address); // transmit to device #112 (0x70)
    // the address specified in the datasheet is 224 (0xE0)
    // but i2c adressing uses the high 7 bits so it's 112
    Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)
    Wire.write(byte(0x51));      // command sensor to measure in "inches" (0x50)
    // use 0x51 for centimeters
    // use 0x52 for ping microseconds
    Wire.endTransmission();      // stop transmitting

    // step 2: wait for readings to happen
    delay(70);                   // datasheet suggests at least 65 milliseconds

    // step 3: instruct sensor to return a particular echo reading
    Wire.beginTransmission(static_address); // transmit to device #112
    Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
    Wire.endTransmission();      // stop transmitting

    // step 4: request reading from sensor
    Wire.requestFrom(static_address, 2);    // request 2 bytes from slave device #112

    // step 5: receive reading from sensor
    if (2 <= Wire.available()) { // if two bytes were received
        reading = Wire.read();  // receive high byte (overwrites previous reading)
        reading = reading << 8;    // shift high byte to be high 8 bits
        reading |= Wire.read(); // receive low byte as lower 8 bits
        output_value = reading;   // print the reading
        //output_value = reading;
    }
    yield();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有匹配的函数可调用未解析的重载函数类型 - No matching function for call to unresolved overloaded function type 没有匹配的 function 可以打电话给<unresolved overloaded function type></unresolved> - no matching function for call to <unresolved overloaded function type> “没有匹配的函数可以调用...未解析的重载函数类型” - “No matching function for call to… unresolved overloaded function type” 没有用于调用std :: transform,未解析的重载函数类型的匹配函数 - No matching function for call to std::transform, unresolved overloaded function type 错误:没有匹配的函数可以调用&#39;sort(...,…, <unresolved overloaded function type> )&#39; - error: no matching function for call to 'sort(…, …, <unresolved overloaded function type>)' 没有匹配的函数来调用&#39;QDomDocument :: createElement( <unresolved overloaded function type> )&#39; - no matching function for call to 'QDomDocument::createElement(<unresolved overloaded function type>)' 重载的电话*** <unresolved overloaded function type> )&#39;不明确 - call of overloaded *** <unresolved overloaded function type>)' is ambiguous 没有匹配的函数来调用&#39;std :: list <int, std::allocator<int> &gt; :: sort( <unresolved overloaded function type> )&#39; - No matching function for call to 'std::list<int, std::allocator<int> >::sort(<unresolved overloaded function type>)' “没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'” - “no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’” 错误:没有匹配的函数调用 &#39;sf::RenderWindow::draw(<unresolved overloaded function type> )&#39; SFML C++ - Error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)' SFML C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM