基本 C++习语/技巧

发布于 2024-08-23 03:12:06 字数 221 浏览 5 评论 0原文

注意:标记为社区 wiki。

最近几天,我意识到我对C++知之甚少。

此外:

  • 使用 STL
  • 实现 RAII
  • 实现引用计数智能指针
  • 编写我自己的基于策略的模板类
  • 重载运算符 << 一个优秀的 C++ 程序员还

必须了解哪些其他技术?

谢谢!

Note: marked as community wiki.

In recent days, I've realized how little I know about C++.

Besides:

  • using the STL
  • implementing RAII
  • implementing ref-counted smart pointers
  • writing my own policy-based template classes
  • overloading operators << for fun

What other techniques are must-know for a good C++ programmer?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

青芜 2024-08-30 03:12:06

我认为这应该涵盖它:

更多 C++ 习语 - 维基教科书

I think this should cover it:

More C++ Idioms - Wikibooks

半城柳色半声笛 2024-08-30 03:12:06
  • OO 设计
  • 类型的异常安全保证(这是大多数设计模式/习惯用法的基础)。
  • 何时使用哪些标准容器
  • Boost
  • OO Design
  • Types of exception safety guarantees (which is what most design patterns/idioms are based on).
  • When to use which standard containers
  • Boost
一向肩并 2024-08-30 03:12:06

前两个是优秀 C++ 程序员“必须了解”的。 “优秀的 C++ 程序员”不会为了好玩而重载运算符。

The first two are 'must know' for a good C++ programmer. 'Good C++ programmers' do not overload operators for fun.

dawn曙光 2024-08-30 03:12:06

基本:

  • RTTI
  • 虚拟函数
  • shared_ptr等
  • 模板
  • 虚拟继承
  • 可变参数宏

也有用:

  • 属性(取决于您的编译器)
  • 可变参数模板
  • 可变参数函数
  • Constexpr(在编译时排序/计算字符串哈希等...但后者与最后一个相关部分)
  • Lambdas

对于脑残或特殊情况有用:

  • CRTP
  • SFINAE
  • inable_if (类型特征)
  • Foreach 宏
  • 用户定义的文字

Basic:

  • RTTI
  • Virtual functions
  • shared_ptr etc
  • Templates
  • Virtual inheriting
  • Variadic macros

Also useful:

  • Attributes (it depends on your compiler)
  • Variadic templates
  • Variadic functions
  • Constexpr (sorting in compile time / calculating hash of strings etc... but the latter is related to the last section)
  • Lambdas

Useful for brainfucking or in special cases:

  • CRTP
  • SFINAE
  • inable_if (type traits)
  • Foreach macro
  • User-defined literals
撩发小公举 2024-08-30 03:12:06

(几乎不是必须知道的,但仍然有用)使用运算符重载和模板元编程编写特定于领域的语言(请参阅 Boost.Spirit 以获得一个很好的示例) - 但这也很容易搬起石头砸自己的脚。

(hardly a must-know, but still useful) Writing domain-specific languages with operator overloading and template metaprogramming (see Boost.Spirit for a nice example) - but this is the kind of thing that makes shooting yourself in the foot easy, too.

随梦而飞# 2024-08-30 03:12:06

我用来提高c++的方法是阅读leveldb的源代码。因为leveldb是产品级别的代码。所以你可以从真实的产品中学习cpp习惯用法和设计模式。让我向您展示一些

Leveldb使用Pimpl习惯用法的示例,几乎在它的所有头文件中,例如table.h table_build.h write_batch.h。直接从代码中可以了解到

Leveldb使用了很多OO设计模式,比如构建模式,表有table_build类来构建表,块有block_build类来构建块

Leveldb也使用了Iterator模式,迭代器make我们用leveldb比较方便。

所以我认为leveldb包含许多C++工程师应该知道的惯用语或设计模式。

The way I used to improve my c++ is reading the source code of leveldb. Because leveldb is a product level code. So you can learn the cpp idiom and design pattern from a real product. Let me show you some example

Leveldb use the Pimpl idiom, almost in all of it's head file, such table.h table_build.h write_batch.h. You can learn from the code directly

Leveldb use many OO design pattern, such as build pattern, the table have the table_build class to build the table, the block have the block_build class to build the block

Leveldb also use the Iterator pattern, the iterator make us use leveldb more convenient.

So I think leveldb contain many idiom or design pattern that c++ engineer should know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文