Arduino方法名称与库函数冲突

Arduino method name clashes with library function

本文关键字:库函数 冲突 方法 Arduino      更新时间:2023-10-16

我有这个简单的blink示例,修改为声明一个类,其唯一的方法签名与延迟库函数的方法签名匹配。它会使Arduino崩溃,除非我重命名方法。我看到Arduino.h头文件有"extern C"链接说明符,所以不应该有任何名称冲突。你能帮我理解这个错误吗?

致意。

class Wrapper
{
public:
  void delay(unsigned long t)
  {
    delay (t); 
  }
};
Wrapper wr;
Wrapper* wrp = ≀

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  wrp->delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  wrp->delay(1000);              // wait for a second
}

列出的代码有堆栈溢出问题。在Wrapper::delay(unsigned long)中,delay(t)再次调用Wrapper::delay,而不是Arduino delay()例程。

如果你想在Wrapper::delay中调用Arduino delay()例程,你需要像这样限定调用:

class Wrapper
{
public:
  void delay(unsigned long t)
  {
    ::delay(t);
  }
};