constant references with typedef and templates in c++

前端 未结 5 1422
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 13:45

I heard the temporary objects can only be assigned to constant references.

But this code gives error

#include     
template

        
5条回答
  •  迷失自我
    2020-11-28 14:02

    Your code gives error because the const qualifier in const ref error is just ignored because 8.3.2/1 says

    Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef (7.1.3) or of a template type argument(14.3), in which case the cv-qualifiers are ignored.`

    So error has type int& not const int& .

提交回复
热议问题