Ambiguity and Complex Types
What if we want to create objects of complex types? What if there's ambiguity when you initialize std::variant? Read below to find out the answers.
We'll cover the following...
We'll cover the following...
Let’s Discuss Ambiguity
What if you have an initialization like:
The value 10.5 could be converted to int or float, and the compiler doesn’t know which
conversion should be applied. It might report a few pages of compiler errors, however.
But you can easily handle such errors by specifying which type you’d like to create:
Let’s Discuss Complex Types
Similarly to std::optional, if you want to efficiently create objects that require several constructor arguments - then use std::in_place_index or std::in_place_type:
For example:
...