-2

Working on making a hash-table. Trying to figure out how to better optimize my table. Found this interesting code, and can not seem to find any C++ documentation explaining how the bottom two lines of this code operate, or why this works. Can someone please explain? Additionally, are there alternative ways to do this same thing and offer more readability?

class Table {
public:
    explicit Table(const int s);
    ~Table();

    Table(const Table&) = delete;
    Table &operator = (const Table&) = delete;
  • 1
    That code is making `Table` non-copyable by deleting the copy constructor and copy-assignment operator. In my opinion this is *the most readable* way to make a class non-copyable – Cory Kramer May 14 '18 at 19:17
  • 3
    See [deleted functions](http://en.cppreference.com/w/cpp/language/function#Deleted_functions). It explicitly marks a function as not callable. In the case of functions that may be generated by the compiler, the compiler doesn't implicitly generate them. – François Andrieux May 14 '18 at 19:17
  • Further reference: http://www.stroustrup.com/C++11FAQ.html#default. – R Sahu May 14 '18 at 19:20

1 Answers1

0

= delete tells the compiler to not generate the specified function for the class, if it's one of the special member functions. Or to remove the function from the class, if it's an inherited function.

As for readability, I honestly don't think you can do it any more clear and explicit than = delete. What do you find to be unclear?

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70