Defining Variants With Constructor Arguments
In Helping The Compiler Help Us With Variants, I introduced the concept of variants with a basic example of how to define and use one. The fun doesn't stop there.
We can take variants a step further by defining them with constructor arguments.
The second variant is defined such that it is paired with some extra data -- a single int
argument.
Here is how we use that variant in our code:
Our switch statement not only matches on that variant, but it makes the int
argument available as a value we can consume in that step of the switch.
Last updated