你的C ++ cheatsheet是什么? [英] What's on your C++ cheatsheet?

查看:137
本文介绍了你的C ++ cheatsheet是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经常,我必须在大多数我编写的代码(不管是工作还是播放)之间切换语言。我发现C ++是这些语言之一,需要大量的智能缓存空间,所以如果我从它的长时间休息,那么我忘了很多细节。即使像在STL容器中添加项目或在各种上下文中使用 static storage关键字的事情都会被混乱(添加 append push ...哦,它 push_back )。

Every so often, I'll have to switch between languages for the majority of the code I write (whether for work or for play). I find that C++ is one of those languages that requires a lot of mental cache space, so if I take a long break from it, then I forget a lot of the details. Even things like adding items to an STL container or using the static storage keyword in various contexts get all jumbled up ("is it add, append, push...oh, it's push_back").

那么,当你写C ++的时候,你喜欢什么样的东西加载到大脑里?

So what essential tidbits do you like to have loaded into your brain when you're writing C++?

编辑:我应该说,我希望能够将此页面加入书签并将其用作我的骗子:)

I should say, I'd like to be able to bookmark this page and use it as my cheatsheet :)

推荐答案

当我从Java切换回C ++时,我喜欢查看 C ++编码标准。Herb Sutter和Andrei Alexandrescu。

When I switch back from Java to C++, I like to review items from C++ Coding Standards by Herb Sutter and Andrei Alexandrescu.

Scott Meyers的有效的C ++

Scott Meyers' Effective C++ series are great for this too.

以下是适用于我的快速基本资料:

Here are quick basic stuffs that work for me:


  • 使用 std :: swap()

  • 如果有疑问,请按照int。 (Scott Meyers)

  • const * 表示常量数据, * const

  • 在具有动态分配数据的类中声明赋值运算符和复制构造函数。

  • C ++将写一个赋值运算符&如果你不自己声明一个复制构造函数。除非你声明它们(私有,很可能),并省略定义它们。

  • 拥有operator =()返回对 *的引用

  • )在Derived的复制构造函数的init列表中。

  • 在Derived的中调用 Base :: operator =(rhs); operator =()

  • 检查 operator =()

  • 不要通过调用复制构造函数实现 operator =()(Herb Sutter,写你知道的,知道你写的内容

  • 记住 RAII

  • 通过引用捕获异常

  • Use std::swap()
  • "When in doubt, do as the ints do." (Scott Meyers)
  • const * means constant data, * const means constant pointer (read the decl. backwards!).
  • Declare an assignment operator and a copy constructor in classes with dynamically assigned data.
  • C++ will write an assignment operator & copy constructor for you if you don't declare one yourself. Except if you declare them (private, most likely) and omit to define them.
  • Have operator=() return a reference to *this
  • Call Base(rhs) in Derived's copy constructor's init list.
  • Call Base::operator=(rhs); in Derived's operator=()
  • Check for assignment to self in operator=()
  • Don't implement operator=() by calling the copy constructor (Herb Sutter, Write what you Know, and Know what you Write)
  • Remember RAII
  • catch exceptions by reference

这篇关于你的C ++ cheatsheet是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆