Self-test questions
- The Rule of Three states that if you define your own destructor for a class, you should also define:
a. Your own copy constructor
b. Your own assignment operator
c. Both a and b
d. Either a or b
- Assuming the class
String
has both copy and move constructors, which of the following does not invoke a move constructor:a.
String s1(getName());
b.
String s2(s1);
c.
String s2(std::move(s1));
d.
String s3("Hello");
- The purpose of
std::move
function is to:a. Move contents of its argument out
b. Create an lvalue reference from an rvalue reference
c. Create an xvalue from an lvalue expression
d. Swap contents of its argument with another object
- In which of the following cases does Return Value Optimization apply?:
a.
return std::string("Hello");
b.
string reverse(string);string a, b;reverse(a + b);
c.
std::string s("Hello");return s;
d.
std::string a, b;return a + b.