What does T&& (double ampersand) mean in C++11?

I’ve been looking into some of the new features of C++11 and one I’ve noticed is the double ampersand in declaring variables, like T&& var. For a start, what is this beast called? I wish Google would allow us to search for punctuation like this. What exactly does it mean? At first glance, it appears … Read more

push_back vs emplace_back

I’m a bit confused regarding the difference between push_back and emplace_back. void emplace_back(Type&& _Val); void push_back(const Type& _Val); void push_back(Type&& _Val); As there is a push_back overload taking a rvalue reference I don’t quite see what the purpose of emplace_back becomes? 7 s 7 In addition to what visitor said : The function void emplace_back(Type&& … Read more

What are the rules about using an underscore in a C++ identifier?

It’s common in C++ to name member variables with some kind of prefix to denote the fact that they’re member variables, rather than local variables or parameters. If you’ve come from an MFC background, you’ll probably use m_foo. I’ve also seen myFoo occasionally. C# (or possibly just .NET) seems to recommend using just an underscore, … Read more

Undefined behavior and sequence points

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 … Read more

Can I call a constructor from another constructor (do constructor chaining) in C++?

As a C# developer I’m used to running through constructors: class Test { public Test() { DoSomething(); } public Test(int count) : this() { DoSomethingWithCount(count); } public Test(int count, string name) : this(count) { DoSomethingWithName(name); } } Is there a way to do this in C++? I tried calling the Class name and using the … Read more