Difference between: void mymodule::step() { ... and void step() override {

Hi, as i am learning, i am asking myself about why i should use one or the other void step
and if one can explain me the difference and the use of it, thx
uriel

You need the class qualifier if you are defining the function outside of the class:

class mymodule ... {
    void step() ... {
        ...
    }
};

vs.

class mymodule ... {
    ...
};

void mymodule::step() ... {
    ...
}

The override modifier tells both the compiler and you, the reader, that the function overrides a virtual function in the base class. It’s useful as documentation as you read the code, but it’s massively useful if the function signature in the base class changes, because the compiler will then report an error rather than silently compiling your function as a plain old member function that doesn’t override anything.

Sidenote: i recommend using Clang++ if you can, and crank the warning flags as high up as you can stand. Use GCC for final distribution if you need to.

  • Performance of GCC vs Clang binaries is debatable, but,
  • Diagnostic info from clang is better in every way.

I had a struct definition with the same name as a global variable (ick, but the plugin SDK demands them) and GCC would give useless errors about “expected a comma here” and would point to the middle of perfectly valid C++ code. Clang would immediately spot that a tag was used ambiguously and cited the offending variable.

1 Like

Thank you very much guys, i did finally understand the point and clean my code ! super

1 Like