Page 1 of 1

ESP32s3 + vscode this 指针问题

Posted: Thu Dec 12, 2024 8:58 am
by nufing
使用 vscode 编写 esp32s3 的代码,

在类里面 判断 if(this == 0) 会报错 error: 'nonnull' argument 'this' compared to NULL,
另外调用空指针的 成员函数 , 在运行时, 报错, 然后整个系统重启, 例如 :

class A
{
public:
int ADD(int a, int b)
{
if(!this)return 0; // 编译时 报错: error: 'nonnull' argument 'this' compared to NULL, 屏蔽后可 正常编译 , 不知道什么原因。
return a + b;
}
};

int main()
{
A* a = (A*)0;
a->Add(1, 2); // 报错, 然后整个系统重启
}

上面的代码, 在其它编译器, 其它 环境能正常工作的, 在这里向高手请教一下, 应该怎么解决?