9

引用类型无法在模板中添加 const 等属性,这情况什么是怎么回事?

 2 years ago
source link: https://www.zhihu.com/question/476815008/answer/2035231815
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

引用类型无法在模板中添加 const 等属性,这情况什么是怎么回事?

template<typename T> void test() { std::cout << std::is_same_v<const T, in…
5
432
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

是的,对引用类型进行add_const操作是空动作。

add_cv Provides the member typedef type which is the same as T, except it has a cv-qualifier added (unless T is a function, a reference, or already has this cv-qualifier)

引用的底层是没有const的说法的,只有顶层有const。换句话说引用本身是const不可修改的,而它引用的对象可以有const属性。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK