class A
{
public:
A() = default;
A(const A&) = delete;
};
class A
{
public:
A() = default;
private:
A(const A&) = delete;
};
I want to extend Daniel Frey's answer. Instead of making deleted methods always public
, I would rather give these methods the access modifier you would (hypothetically) give these methods if they would not be deleted. (I do not like always in case a programmer has an option. If it would indeed be carved in stone to make deleted methods public
, it should be enforced by the language itself.)
Some rules of thumb/guidelines:
public
in concrete and abstract classes for most cases.public
in concrete classes for most cases.protected
in abstract classes for most cases.private
in concrete final
classes that can only be instantiated by friends
for most cases.In all cases, you make an announcement to the appropriate users of a class instead of all users of a class.