::的三处用法
1.使用全局变量,::a
2.使用namespace中的变量 std::a
3.使用类中的变量 C::a
explicit
防止隐式转换
std::tie
参数太多,批量打包赋值。
string 和 char* 为什么同时存在?
网络库经常要操作内存,char*时,可以用mem函数集操作内存,一般字符串还是用string来操作。
const auto&, auto&&, auto
auto => will copy the vector, but we wanted a reference
auto& => will only bind to modifiable lvalues
const auto& => will bind to anything but make it const, giving us const_iterator
const auto&& => will bind only to rvalues
So for this, auto&& works perfectly! An example of using auto&& like this is in a range-based for loop.
什么时候指针,什么时候引用?
首先裸指针要少用,除非对面是单例的,不然最好使用智能指针或者直接构造一个对象。
然后,作为参数时,多多使用引用而非指针,内存泄漏挺烦。
引用是为了实现操作子重载引入的,但指针真的太灵活了
什么时候用指针最佳?要在堆上申请大内存的时候,栈是比较小的。