-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
The advent of variadic templates in C++11 has made it necessary to ensure there is a way for the semantics at the call site of a function to be conveyed throughout the call chain. This might seem abstract but it’s quite real and has implications on the effect of function calls.
Consider the following class:
#include <string>
struct X {
X(int, const std::string&); // A
X(int, std::string&&); // B
// ... other constructors and various members
}; This class exposes at least two constructors, one that takes an int and const string& as argument and another that takes an int and a string&& instead. To make the example more general, we’ll also suppose the existence of other X constructors that we might want to call while still focusing on these two. If we called these two constructors explicitly, we could do so with the following:
X x0{ 3, "hello" }; /...