harttle / harttle.github.io

Harttle Land 的源码和文章
https://harttle.land
Creative Commons Attribution 4.0 International
122 stars 32 forks source link

2015/09/09/effective-cpp-42 #166

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Effective C++ 42:typename 的两种用法 | Harttle Land

模板参数前的typename和class没有任何区别;但 typename还可以用来帮编译器识别嵌套从属类型名称,基类列表和成员初始化列表除外。

https://harttle.land/2015/09/09/effective-cpp-42.html

otakutyrant commented 2 years ago

typedef & typename,合体!

otakutyrant commented 2 years ago

可以用 using std::iterator_traits<Iter>::value_type = value_type 代替 typedef typename std::iterator_traits<Iter>::value_type 吗?

ZAKERR commented 1 year ago

大多数的特殊约定,都是被逼无奈的选择 其实这里少介绍了一个背景,为什么C::const_iterator编译器可能会认为是一个变量呢? 因为用 ::代表作用域符,作用域下可能也函数,也变量,也有类型。编译器此时就会遇到歧义 为什么又会出现例外条件呢?初始化列表是什么?初始化列表中除了()括号内,其他地方不允许出现解析为变量的情况