Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ discards qualifiers

Tags:

c++

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

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

like image 460
Anthony Avatar asked Jan 17 '14 15:01

Anthony


2 Answers

BSPArduino::enableWdt() is a non-const method. If you try and call a non-const method from a const one you will get this error.

Essentially the error is trying to tell you that you are discarding the constness of "this".

like image 167
Bids Avatar answered Nov 18 '22 17:11

Bids


You're trying to call a non-const function from a const member function; that's not allowed.

If possible, add a const qualifier to enableWdt. 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.

like image 4
Mike Seymour Avatar answered Nov 18 '22 17:11

Mike Seymour