Passing pointers to functions

Don’t!
▪Ownership is ambiguous
▪It implies the argument can be null
Prefer a reference if the function is only observing the argument
Use a unique_ptr or auto_ptr if you pass ownership to the function
Use a shared_ptr if you want (really want) to share ownership with the function

Use a weak_ptr if the function wants to keep the reference and observe it


Returning pointers from functions
Don’t!
▪Ownership is ambiguous
▪It implies the return can be null
▪Encourages the caller to keep the pointer (almost always)
Prefer a const reference
Use a unique_ptr or auto_ptr if you pass ownership to the caller
Use a shared_ptr if you want (really want) to share ownership with the caller
Use a weak_ptr if the caller wants to keep the reference and observe it


Functional programming (Haskell)
Pure functions
Declare if you have side effects
▪ A member function is const except otherwise needed
Don’t return const types by value – RVO & rvalues.
const std::string GetName() const;
But do return const refs


Includes
Const correctness
Pass by reference
Projects – premake
Function Names
▪see FindOrderedSubstringsInWord
Singleton
Statics in headers
Unit tests
Warnings
Defines for configuring things (static libs!!)
Memory allocation habbits


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值