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

前端 未结 11 1102
伪装坚强ぢ
伪装坚强ぢ 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:35

    @jonathan-oconnor points out that you can use the [[deprecated]] attribute introduced in C++14 to produce a very clean solution:

    template
    [[deprecated]] constexpr void printType(T const&) {}
    

    Unfortunately though, the diagnostic emitted by MSVC doesn't mention the type. (example)

提交回复
热议问题