简体   繁体   English

C ++丢弃限定符

[英]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.

相关问题 C++ 映射访问丢弃限定符 (const) - C++ map access discards qualifiers (const) 错误传递 const 作为丢弃限定符 C++ 的这个参数 - error passing const as this argument of discards qualifiers C++ c ++ QVector / Vector问题... const ...丢弃限定符 - c++ QVector/Vector issues… const… discards qualifiers QT&C ++:传递&#39;const QString&#39;会丢弃限定词 - QT & C++ : Passing 'const QString' discards qualifiers C ++:将const作为&#39;this&#39;参数传递...丢弃涉及Json的限定符 - C++: passing const as 'this' argument … discards qualifiers involving Json C ++中虚函数和/或const的“丢弃限定符”错误 - “Discards qualifiers” error with virtual function and/or const in c++ 抛弃预选赛 - discards qualifiers 奇怪的C ++错误:test.cpp:15:错误:将'const *'作为'*'的'this'参数传递丢弃限定符 - An odd C++ error: test.cpp:15: error: passing ‘const *’ as ‘this’ argument of ‘*’ discards qualifiers C ++ Boost-序列化错误-将&#39;const B&#39;作为&#39;this&#39;参数传递会丢弃限定符 - C++ Boost - serialization error - passing ‘const B’ as ‘this’ argument discards qualifiers C ++错误:传递&#39;const std :: vector <Node> &#39;作为&#39;this&#39;参数丢弃限定词[-fpermissive] - c++ error: passing ‘const std::vector<Node>’ as ‘this’ argument discards qualifiers [-fpermissive]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM