Hacker News new | ask | show | jobs
by jpm48 1701 days ago
I put

private : myclass(const &myclass )=delete;

Just to be safe :-)

3 comments

Funny thing there is that one could read that as saying that the copy constructor's deletion is private and therefore still accessible in the public interface. I wouldn't put it past C++ to do something as crazy as that.
IIRC this will make the compiler error less helpful than it could be? I think you'd get an "attempt to use private member" instead of "attempt to use deleted member". End result is probably the same, but it feels like you're not saying what you mean with the code.

Edit: NVM, looks like all major compilers will say that the copy ctor is deleted. https://godbolt.org/z/jTd3714Tb

clang-tidy will ask that you put in the full set.

  Foo() = delete;
  Foo(const Foo& orig) = delete;
  Foo(Foo&& orig) = delete;
  Foo operator=(const Foo &other) = delete;
  Foo operator=(Foo &&other) = delete;
(add const to taste)