c++ - 静态函数中对静态变量的未定义引用
问题描述
大家好,我正在使用 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();
}
解决方案
推荐阅读
- php - 当请求来自移动设备时 session_start() 无法访问 /tmp 目录
- python - 有没有办法为python的cmd模块中的函数添加值(使用程序时)
- python - 从 Lambda 函数 (AWS) 的用户列表中获取 UserId
- git - 使用两个不同的 Github 帐户
- python - 将列表值合并到 1 个字符串中
- regex - Python:删除所有以大写字母开头且标点符号后不出现的单词
- html - 如何在angular6中将记录从一个网格推送到另一个网格
- typescript - Mongoose 的 loadClass() 和 TypeScript
- c++ - envp 代表什么?
- typescript - 路由器子组件未绑定