c++-faq

Undefined behavior and sequence points

梦想的初衷 提交于 2019-11-25 21:29:44
问题 What are \"sequence points\"? What is the relation between undefined behaviour and sequence points? I often use funny and convoluted expressions like a[++i] = i; , to make myself feel better. Why should I stop using them? If you\'ve read this, be sure to visit the follow-up question Undefined behavior and sequence points reloaded . (Note: This is meant to be an entry to Stack Overflow\'s C++ FAQ. If you want to critique the idea of providing an FAQ in this form, then the posting on meta that

The Definitive C++ Book Guide and List

时光怂恿深爱的人放手 提交于 2019-11-25 21:29:24
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written C++ book. It is way too big and complex for doing this. In fact, it is so big and

Undefined behavior and sequence points reloaded

时光怂恿深爱的人放手 提交于 2019-11-25 20:23:52
Consider this topic a sequel of the following topic: Previous installment Undefined behavior and sequence points Let's revisit this funny and convoluted expression (the italicized phrases are taken from the above topic *smile* ): i += ++i; We say this invokes undefined-behavior. I presume that when say this, we implicitly assume that type of i is one of the built-in types. What if the type of i is a user-defined type? Say its type is Index which is defined later in this post (see below). Would it still invoke undefined-behavior? If yes, why? Is it not equivalent to writing i.operator+=(i

What C++ Smart Pointer Implementations are available?

醉酒当歌 提交于 2019-11-25 20:08:37
Comparisons, Pros, Cons, and When to Use? This is a spin-off from a garbage collection thread where what I thought was a simple answer generated a lot of comments about some specific smart pointer implementations so it seemed worth starting a new post. Ultimately the question is what are the various implementations of smart pointers in C++ out there and how do they compare? Just simple pros and cons or exceptions and gotchas to something you might otherwise think should work. I've posted some implementations that I've used or at least glossed over and considered using as an answer below and my