[SOLVED] error: non-member function cannot have cv-qualifier

Hello I am getting this error that has to do with the wait function. I have tried commenting out the bits that use the wait function one by one and compiling the code and I receive the same error every time. I have tried copying and pasting my code here but it exceeds the character limit. I tried removing files of code from the code list and it was still over the limit. Therefore I decided to download the sketch from arduino create (where I am editing the sketch) and upload it here :).

Here is the error:

/tmp/611229924/build/sketch/Timing.cpp:3:67: error: non-member function 'bool wait(long unsigned int&, long unsigned int)' cannot have cv-qualifier

bool wait(unsigned long& prev_time, unsigned long const interval) const

^

exit status 1

Bicycle_computer_nextion.zip (16.2 KB)

The ending const states that you will not modify any member variables of the class the wait() function belongs to. But there is no such class (it’s not a member function probably) so you get this error

Get rid of the const at the end

bool wait(unsigned long& prev_time, unsigned long const interval) [s][color=red][b]const[/b][/color][/s]

J-M-L:
The ending const states that you will not modify any member variables of the class the wait() function belongs to. But there is no such class (it’s not a member function probably) so you get this error

Get rid of the const at the end

bool wait(unsigned long& prev_time, unsigned long const interval) [s][color=red][b]const[/b][/color][/s]

Ah ok. Thanks a lot it is greatly appreciated. Last time I posted a zip file it wasn't welcomed. I was under the impression the const meant that the return value is const. Welp that wouldn't make much sense since that would be the return expression. Thanks!

I did not open the zip :slight_smile: and it’s indeed not a great practice if you can avoid it

Comment was just based on what you shared which was likely enough

There is limited conceptual value in telling the compiler what you’ll return is constant unless you return a reference... (a bool will just be put in the stack to be read by the caller... ) but in that case the const goes in front, where you define the returned type

The idea of const member functions is not allow them to modify the object on which they are called in which case const is at the end