jeudi 8 juillet 2021

auto with ternary operator and nullptr

Can I use auto with such usage of the ternary operator?

auto obj = some_cond ? static_cast<className*>(baseClassObj) : nullptr;

It compiles in Visual Studio, and the code works OK, but can there be any unexpected side effects? Or, will auto here always be className* and I can relax and write such code? Or, with the ternary operator, is it better to write this?

className* obj = some_cond ? static_cast<className*>(baseClassObj) : nullptr;

Aucun commentaire:

Enregistrer un commentaire