我正在尝试创建一个处理事件的类。 class2
表示事件,class1
是存储和处理事件的结构。这是我用来证明这个概念的简化代码,它不起作用:
class TestClass2{
public:
TestClass2(int x,int y,int z) {
_x=x;
_y=y;
_z=z;
}
private:
int _x,_y,_z;
};
class TestClass{
public:
void putVal(TestClass2 x)volatile{
// The error is happening here.
test=x;
return;
}
private:
TestClass2 test;
};
volatile TestClass testObj = TestClass();
IRAM_ATTR void testISR(){
TestClass2 testInput = TestClass2(1,2,3);
testObj.putVal(testInput);
}
uint8_t EventPin = 5;
void setup() {
Serial.begin(115200);
pinMode(EventPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(EventPin), testISR, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(millis());
delay(1000);
}
我收到此错误:
Compilation error: passing 'volatile TestClass2' as 'this' argument discards qualifiers \[-fpermissive\]
如果我用整数数组替换 TestClass2
数组,它就可以工作。
我哪里出错了?
最佳答案
您还需要使测试类中的函数具有 volatile 。
如果您在那里查找错误,您会发现 this ,这可以回答您的问题。
关于c++ - 为什么我的 C++ Arduino 程序在写入数组时会中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76201994/