Arduino 方法名称与库函数冲突

Arduino method name clashes with library function

我有这个简单的眨眼示例,修改为声明一个 class,其唯一方法签名与延迟库函数的方法签名匹配。除非我重命名该方法,否则它会使 Arduino 崩溃。我看到 Arduino.h header 有 "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() routine

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

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