Effective Modern C++

static_cast<int>()而非(int)

这是新写法。如:

float floatPi = 3.14f;
int intPi = static_cast<int>(floatPi);

与之类似的还有:dynamic_castconst_castreinterpret_cast

using而非typedef

这也是新写法。如:

using VI = std::vector<int>;
//而不是 typedef std::vector<int> VI;
VI vi;
不要using namespace std

之所以要设置std这个命名空间,就是为了防止重名
using namespace std则将这一努力毁之一旦
如果输入输出要打std::太麻烦,建议这样做:

using std::cin;
using std::cout;
位域

这个看上去很不错。
Lnk

拒绝enum,改用enum class
  1. 命名空间不重合
  2. 防止意外转换
右值引用、移动语义和完美转发

可以说是Effective Modern C++关于这一块的整理。

C++14引入std::quoted()用于给字符串添加双引号

std::quoted("a"); --> "\"a\""

Coming to grips with C++11 and C++14 is more than a matter of familiarizing yourself with the features they introduce (e.g., auto type declarations, move semantics, lambda expressions, and concurrency support). The challenge is learning to use those features effectively—so that your software is correct, efficient, maintainable, and portable. That’s where this practical book comes in. It describes how to write truly great software using C++11 and C++14—i.e. using modern C++. Topics include: The pros and cons of braced initialization, noexcept specifications, perfect forwarding, and smart pointer make functions The relationships among std::move, std::forward, rvalue references, and universal references Techniques for writing clear, correct, effective lambda expressions How std::atomic differs from volatile, how each should be used, and how they relate to C++'s concurrency API How best practices in "old" C++ programming (i.e., C++98) require revision for software development in modern C++ Effective Modern C++ follows the proven guideline-based, example-driven format of Scott Meyers' earlier books, but covers entirely new material. "After I learned the C++ basics, I then learned how to use C++ in production code from Meyer's series of Effective C++ books. Effective Modern C++ is the most important how-to book for advice on key guidelines, styles, and idioms to use modern C++ effectively and well. Don't own it yet? Buy this one. Now". -- Herb Sutter, Chair of ISO C++ Standards Committee and C++ Software Architect at Microsoft
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值