4
When I was learning C++ I read in a book in the polymorphism chapter about virtual functions that the virtual keyword was meant to indicate that that function was going to be overwritten in another part of the code, since then I started adding virtual in all my header settings.
One day I was in an android studio project where I used NDK, when I received an error similar to this:
The class has virtual functions, but does not have a destructor virtual
Searching about this error I soon noticed that people only used the virtual keyword in derived or abstract classes, but I soon remembered seeing a virtual function in a class of a Unreal engine 4 project that was not overwritten from another class, so using virtual functions in non-derivative classes is correct or just ignored by desktop compilers? (Note: I use MSVC, I don’t remember this error in g++ either, android studio uses Clang)
"since then I started adding virtual in all my header settings" - this sounds like abuse of functionality, use without reason.
– Mário Feroldi