C++ 学习期间遇到的符号、用法问题

::的三处用法

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.

什么时候指针,什么时候引用?

首先裸指针要少用,除非对面是单例的,不然最好使用智能指针或者直接构造一个对象。

然后,作为参数时,多多使用引用而非指针,内存泄漏挺烦。

引用是为了实现操作子重载引入的,但指针真的太灵活了

什么时候用指针最佳?要在堆上申请大内存的时候,栈是比较小的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值