Monday, July 31, 2017

C++11: =delete

Specifying =delete for any of the compiler-generated constructors or assignment operators, makes them unavailable. Here is an example:
#include <iostream>
class A
  A() {std::cout << "Default CTOR called; ";}
  A(const A& a) = delete;
int main()
  A a1;
  // A a2(a1); // This line does not compile because of " = delete' above.
  return 0;
// Output: Default CTOR called

No comments:

Post a Comment