首页 > 解决方案 > 静态函数中对静态变量的未定义引用

问题描述

大家好,我正在使用 PlatformIO 对 arduino 进行编程。问题是我有一个静态 void 应该更改静态变量但是在编译代码后我遇到了 vscode 中的错误说:

c:/users/hossein/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\huzzah\src\main.cpp.o:(.text.loop+0x0): undefined reference to sampleClass::buffer' collect2.exe: error: ld returned 1 exit status *** [.pio\build\huzzah\firmware.elf] Error 1

我还在下面的框中包含了我的代码。如果有人能给我一个提示,让我可以让我的脚本正常工作,我将不胜感激。

#include <Arduino.h>

class sampleClass
{
public:
  //variables
  static int buffer[10];
  static float ratio;
  int64_t data;
  // functions
  static void filling()
  {
    sampleClass::buffer[1] = sampleClass::buffer[1] + 1;
    printf(" the value of the buffer in the scope of the function is : %f \n", double(buffer[1]));
  };

private:
};

sampleClass a;

void setup()
{
  // put your setup code here, to run once:
}

void loop()
{
  // put your main code here, to run repeatedly:
  a.sampleClass::filling();
}

标签: c++functionclassvariablesstatic

解决方案


推荐阅读