ProgrammingVery hardProduct-company placement · C++
How many of these statements about implicitly generated special members in C++11 and later are correct? (i) If a class declares a copy constructor, no move constructor is implicitly declared. (ii) If a class declares a move constructor, its implicit copy constructor is defined as deleted. (iii) A user-declared destructor prevents the implicit declaration of a move constructor. (iv) Declaring any constructor suppresses the implicit copy constructor.
- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: A. 3
(i), (ii) and (iii) are correct, which is why an object of a class with only a destructor is copied when moved. (iv) is false: declaring a constructor suppresses only the implicit DEFAULT constructor.
More OOP with C++ and Java questions
- What happens when this is compiled? cpp struct A { A(int) { } }; int main() { A a; }
- What is printed? cpp struct B { virtual void f() { cout << "B"; } }; struct D : B { void f() override { cout << "D"; } }; int main() {…
- What is printed? cpp template <class T> struct Base { void hi() { staticcast<T>(this)->impl(); } void impl() { cout << "B"; } }; struct X…
- What happens? cpp template <class T> T mx(T a, T b) { return a > b ? a : b; } int main() { cout << mx(3, 7); // L1 cout << mx(1, 2.5); //…
- What is printed? cpp struct A { A() { cout << "A"; } ~A() { cout << "a"; } }; struct B { B() { cout << "B"; } ~B() { cout << "b"; } }…
- Which line fails to compile? cpp string a = "a" + "b"; // L1 string b = string("a") + "b"; // L2 string c = "a" + string("b"); // L3…