{"action":"opened","issue":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/177","labels_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/177/labels{/name}","comments_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/177/comments","events_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/177/events","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/177","id":108551518,"number":177,"title":"C.67: A base class should suppress copying, and provide a virtual clone instead if \"copying\" is desired","user":{"login":"andralex","id":566679,"avatar_url":"https://avatars.githubusercontent.com/u/566679?v=3","gravatar_id":"","url":"https://api.github.com/users/andralex","html_url":"https://github.com/andralex","followers_url":"https://api.github.com/users/andralex/followers","following_url":"https://api.github.com/users/andralex/following{/other_user}","gists_url":"https://api.github.com/users/andralex/gists{/gist_id}","starred_url":"https://api.github.com/users/andralex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andralex/subscriptions","organizations_url":"https://api.github.com/users/andralex/orgs","repos_url":"https://api.github.com/users/andralex/repos","events_url":"https://api.github.com/users/andralex/events{/privacy}","received_events_url":"https://api.github.com/users/andralex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-27T18:11:52Z","updated_at":"2015-09-27T18:11:52Z","closed_at":null,"body":"Two issues:\r\n\r\n* A base class may choose to define copying as a protected operation, and use it inside clone(). Otherwise, implementing clone() efficiently and without code duplication is difficult.\r\n\r\n* The Checked Clone idiom should be mentioned:\r\n\r\n```C++\r\nclass S {\r\nprotected:\r\n  virtual std::unique_ptr<S> cloneImpl() const;\r\npublic:\r\n  std::unique_ptr<S> clone() const {\r\n    auto result = cloneImpl();\r\n    assert(typeid(*this) == typeid(*result.get()));\r\n    return result;\r\n  }\r\n  ...\r\n};\r\n```\r\n\r\nEnsures the result type is identical with the incoming type."}}