I made a class that inherits from a superclass and need to overwrite some functions. Both
override void example_function();
and
virtual void example_function();
seems to work. What is the difference and which one should I use?
I made a class that inherits from a superclass and need to overwrite some functions. Both
override void example_function();
and
virtual void example_function();
seems to work. What is the difference and which one should I use?
In the superclass, the function should be declared as
virtual void example_function();
In the class that inherits, override should almost always be used:
override void example_function();
If for any reason example_function is updated / removed in the superclass, the developer will get a compile error in all classes that overrides the virtual function. If virtual was used, no compile error would appear and the developer would be lured into false sense of security.