Using 'auto' type deduction - how to find out what type the compiler deduced?

前端 未结 11 1072
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 07:54

How can I find out what type the compiler deduced when using the auto keyword?

Example 1: Simpler

auto tickTime = 0.001;

W

11条回答
  •  隐瞒了意图╮
    2021-01-30 08:39

    A low tech solution is hover the mouse over nextTickTime which in some GUIs gives the type else set a . after nextTickTime in the cout and select a reasonable looking value or function.

    In general if You know what type You get use auto if you don't know it don't use it. Which is a bit counter intuitive.

    So if you know its a interator just use auto to reduce the incantations, if the result is some unknown type you have to find out what it is before using auto.

    See also Herb, Andrei and Scott discussing auto

提交回复
热议问题