I have a NonCopyable class and an Application class derived from NonCopyable:
class NonCopyable
{
public:
NonCopyable() = default;
~NonCopyable() = default;
NonCopyable(NonCopyable const&) = delete;
NonCopyable& operator =(NonCopyable const&) = delete;
NonCopyable(NonCopyable&&) = delete;
NonCopyable& operator=(NonCopyable&&) = delete;
};
class Application : public NonCopyable
{
public:
~Application() { /* ...delete stuff... */ }
};
As you see, I don't need to redeclare deleted move constructors or assignment operators as I've declared them in the base class. But why does Resharper suggest me to declare other special member functions? It said:
Class
Applicationdefines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [hicpp-special-member-functions].There're also [cppcoreguidelines-special-member-functions] reminders with the same message.
The current workaround is to explicitly write all of them to make the warning go away:
class Application : public NonCopyable
{
public:
~Application() { /* ...delete stuff... */ }
Application(Application const&) = delete;
Application& operator =(Application const&) = delete;
Application(Application&&) = delete;
Application& operator=(Application&&) = delete;
};
Aucun commentaire:
Enregistrer un commentaire