# Virtual vs override functions

**URL:** <https://quantlab.discourse.group/t/virtual-vs-override-functions/50>\
**Category:** Qlang Language\
**Created:** [April 18, 2024, 7:25am UTC](https://quantlab.discourse.group/t/virtual-vs-override-functions/50 "2024-04-18T07:25:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casperfdr](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@casperfdr](https://quantlab.discourse.group/u/casperfdr)\
**Post date:** [April 18, 2024, 7:25am UTC](https://quantlab.discourse.group/t/virtual-vs-override-functions/50/1 "2024-04-18T07:25:07Z")

</div>

I made a class that inherits from a superclass and need to overwrite some functions. Both

```auto
override void example_function();

```

and

```auto
virtual void example_function();

```

seems to work. What is the difference and which one should I use?

---

<div class="post-metadata">

**Author:** ![kim](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kim](https://quantlab.discourse.group/u/kim)\
**Post date:** [April 18, 2024, 12:25pm UTC](https://quantlab.discourse.group/t/virtual-vs-override-functions/50/2 "2024-04-18T12:25:20Z")

</div>

In the superclass, the function should be declared as

```auto
virtual void example_function();

```

In the class that inherits, **override** should almost always be used:

```auto
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.
