What does 'override' do?

On another forum, I saw someone post a program that had
void setup() override {
void loop() override {

What does override do in this case?

Not a clue, you would need to post the code and a link to where you found it.

is to indicate explicitly that you want to override given method, if it is not declared virtual you will get error

Wait a minute... there are other forums?

I just tried it with the Arduino IDE 1.8.15 and the UNO board. I get this error:

virt-specifiers in 'setup' not allowed outside a class definition

However, if I precede void setup() override with the following, then it compiles:

#define override

which is neither surprising nor useful.

override seems to be a function created by the author. It can do anything the imagination of the author can produce.

I'm guessing you think it might be a C, C++, arduino macro, It doesn't appear to be.

Killzone_kid appears to be more correct:

override identifier in C++ - GeeksforGeeks

Um. It doesn't sound like it would be at all applicable to setup() or loop() (which are not member functions of a class, nor virtual...)

That's what I thought, but his program had other errors, like not declaring an object from a library.
I don't want to hash his program here, I just wanted to know if I was missing a property of Arduino C++.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.