[英]C++ discards qualifiers
I have this error: 我有这个错误:
BSPArduino.cpp:316: error: passing 'const BSPArduino' as 'this' argument of 'virtual void BSPArduino::enableWdt(const WATCHDOG_TIMER_DELAY&, const ___bool&)' discards qualifiers
BSPArduino.cpp:316:错误:将'const BSPArduino'作为'this'参数传递给'virtual void BSPArduino :: enableWdt(const WATCHDOG_TIMER_DELAY&,const ___ bool&)'丢弃限定符
This method is define like that: 这个方法定义如下:
void BSPArduino::enableWdt(const WATCHDOG_TIMER_DELAY &delay, const ___bool &enable)
I want to call it like that: 我想这样称呼它:
enableWdt(this->watchdogTimer, ___false);
With: 附:
WATCHDOG_TIMER_DELAY watchdogTimer;
I don't understand why this build error... 我不明白为什么这个构建错误...
Thank you so much for your help 非常感谢你的帮助
Anthony 安东尼
BSPArduino::enableWdt() is a non-const method. BSPArduino :: enableWdt()是一种非const方法。 If you try and call a non-const method from a const one you will get this error.
如果您尝试从const中调用非const方法,则会出现此错误。
Essentially the error is trying to tell you that you are discarding the constness of "this". 本质上,错误是试图告诉你,你正在丢弃“这个”的常量。
You're trying to call a non- const
function from a const
member function; 你试图从
const
成员函数调用非const
函数; that's not allowed. 这是不允许的。
If possible, add a const
qualifier to enableWdt
. 如果可能,请为
enableWdt
添加const
限定符。 If that's not possible (because it modifies the object) then you'll have to either remove the const
qualifier from the calling function, or restructure the code so that enableWdt
is called from somewhere else. 如果那是不可能的(因为它修改了对象),那么你必须从调用函数中删除
const
限定符,或者重构代码以便从其他地方调用enableWdt
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.