The relationship between auto and decltype

后端 未结 5 2122
礼貌的吻别
礼貌的吻别 2020-12-12 17:35

Is

auto x = initializer;

equivalent to

decltype(initializer) x = initializer;

or

decltype         


        
5条回答
  •  难免孤独
    2020-12-12 18:06

    1. If initializer is an array then decltype(x) or decltype((x)) don't work simply on it. However auto will be deduced to a pointer.
    2. If initializer is a function then applying decltype(fp) will deduce to the function type however, auto will deduce to its return type.

    So in general auto cannot be considered as a replacement of any decltype() version you asked.

提交回复
热议问题