One of the arguably more obvious features introduced in C++11 is the ability to specify keyword default for special member functions. The default keyword instructs the compiler to define the function as if it implicitly would have. In the case of a copy constructor and a POD class, the compiler would define a function to copy each member. The main reason you’d want to do this yourself, as opposed to letting the compiler implicitly declare and define it for you, is if the compiler refuses to do so. For example, if there’s a move operation declared in the class. This is based on the rule of Three (now rule of Five). The idea is that if you declare you own version of the move operator for the class, the default copy constructor may not be appropriate. But this may be old news so let’s move on.
Continue reading “default – it’s not (just) syntactic sugar“