jeudi 4 juin 2020

auto and {}-lists question regarding Stroustrup C++ book

The following appears in Stroustrup C++ 4th Ed. Page 164.

T v3 = f();
T v3 {f()}; // works if and only if the type of f() can be implicitly converted to a T

auto v3 = f(); // v3 is of some appropriate type

Does anyone have an example of what type T could be for these examples?

My understanding of assigning functions to a variable are as follows:

void (*fptr)(void) = &f;

Unfortunately this is not in the form of RHS f(). So I'm a bit confused here on use cases of the above examples.

Thanks

Aucun commentaire:

Enregistrer un commentaire