{"id":3081,"date":"2018-07-26T20:00:57","date_gmt":"2018-07-26T18:00:57","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=3081"},"modified":"2024-05-14T07:57:54","modified_gmt":"2024-05-14T05:57:54","slug":"cpp-special-member-function-rules","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/","title":{"rendered":"C++ rules for special member functions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">C++ has several special member functions that are defined by the compiler even if not defined by the user. These special member functions are the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/default_constructor\" target=\"_blank\" rel=\"noopener\">default constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/copy_constructor\" target=\"_blank\" rel=\"noopener\">copy constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/as_operator\" target=\"_blank\" rel=\"noopener\">copy assignment operator<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/move_constructor\" target=\"_blank\" rel=\"noopener\">move constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/move_operator\" target=\"_blank\" rel=\"noopener\">move assignment operator<\/a>, and the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/destructor\" target=\"_blank\" rel=\"noopener\">destructor<\/a>. However, there are many rules for what is defined and in which circumstances. For instance, if no special member function is defined by the user then all of them are implicitly defined by the compiler. On the other hand, if a copy constructor or copy assignment operator is defined by the user, then the move constructor and move assignment operator are not defined by the compiler.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To make it easier to comprehend all the rules, the following table describes what is defined by the compiler based on what is defined by the user.<\/p>\n\n\n\n<table class=\"wp-block-advgb-table advgb-table-frontend\"><thead><tr><th><\/th><th style=\"border-bottom-color:#000\"><strong>Default constructor<\/strong><\/th><th style=\"border-bottom-color:#000\"><strong>Copy constructor<\/strong><\/th><th style=\"border-bottom-color:#000\"><strong>Copy operator=<\/strong><\/th><th style=\"border-bottom-color:#000\"><strong>Move constructor<\/strong><\/th><th style=\"border-bottom-color:#000\"><strong>Move operator=<\/strong><\/th><th style=\"border-bottom-color:#000\"><strong>Destructor<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Nothing<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Any constructor<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Default constructor<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Copy constructor<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#abb8c3\">NO<\/td><td style=\"background-color:#fcb900\">YES<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Copy operator=<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#fcb900\">YES<\/td><td style=\"background-color:#abb8c3\">NO<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Move constructor<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#cf2e2e\">DELETED<\/td><td style=\"background-color:#cf2e2e\">DELETED<\/td><td style=\"background-color:#abb8c3\">NO<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Move operator=<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#cf2e2e\">DELETED<\/td><td style=\"background-color:#cf2e2e\">DELETED<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#abb8c3\">NO<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><\/tr><tr><td>Destructor<\/td><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"background-color:#fcb900\">YES<\/td><td style=\"background-color:#fcb900\">YES<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#cf2e2e\">NO<\/td><td style=\"background-color:#abb8c3\">NO<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\">In the table above, on the horizontal, we have the special member functions that the compiler defines and on the vertical the functions the user may define. You should read the table as follows:<\/p>\n\n\n\n<table class=\"wp-block-advgb-table advgb-table-frontend\"><tbody><tr><td style=\"background-color:#7bdcb5\">YES<\/td><td style=\"padding-top:1px;padding-right:1px;padding-bottom:1px;padding-left:1px;vertical-align:middle\">the special member function is defined by the compiler<\/td><\/tr><tr><td style=\"background-color:#cf2e2e\">NO<\/td><td>the special member function is not defined by the compiler<\/td><\/tr><tr><td style=\"background-color:#abb8c3\">NO<\/td><td>the special member function is not defined by the compiler since it is defined by the user<\/td><\/tr><tr><td style=\"background-color:#fcb900\">YES<\/td><td>the special member function is defined by the compiler but this is deprecated and may be removed in the future<\/td><\/tr><tr><td style=\"background-color:#cf2e2e\">DELETED<\/td><td>the special member function is defined by the compiler as deleted<\/td><\/tr><\/tbody><\/table>\n","protected":false},"excerpt":{"rendered":"<p>C++ has several special member functions that are defined by the compiler even if not defined by the user. These special member functions are the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/default_constructor\" rel=\"noopener\" target=\"_blank\">default constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/copy_constructor\" rel=\"noopener\" target=\"_blank\">copy constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/as_operator\" rel=\"noopener\" target=\"_blank\">copy assignment operator<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/move_constructor\" rel=\"noopener\" target=\"_blank\">move constructor<\/a>, the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/move_operator\" rel=\"noopener\" target=\"_blank\">move assignment operator<\/a>, and the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/destructor\" rel=\"noopener\" target=\"_blank\">destructor<\/a>. However, there are many rules for what is defined and in which circumstances. For instance, if no special member function is defined by the user then all of them are implicitly defined by the compiler. On the other hand, if a copy constructor or copy assignment operator is defined by the user, then the move constructor and move assignment operator are not defined by the compiler. To make it easier to comprehend all the rules, the following table describes what is defined by the compiler based on what is defined by the user.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[451,345],"class_list":["post-3081","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-c11"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,c++11\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"C++ rules for special member functions\" \/>\n\t\t<meta property=\"og:description\" content=\"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2018-07-26T18:00:57+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2024-05-14T05:57:54+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"C++ rules for special member functions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#article\",\"name\":\"C++ rules for special member functions\",\"headline\":\"C++ rules for special member functions\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2018-07-26T20:00:57+02:00\",\"dateModified\":\"2024-05-14T07:57:54+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":7,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#webpage\"},\"articleSection\":\"C++, C++, C++11\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#listItem\",\"name\":\"C++ rules for special member functions\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#listItem\",\"position\":5,\"name\":\"C++ rules for special member functions\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/\",\"name\":\"C++ rules for special member functions\",\"description\":\"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/07\\\/26\\\/cpp-special-member-function-rules\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2018-07-26T20:00:57+02:00\",\"dateModified\":\"2024-05-14T07:57:54+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"C++ rules for special member functions","description":"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/","robots":"max-image-preview:large","keywords":"c++,c++11","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#article","name":"C++ rules for special member functions","headline":"C++ rules for special member functions","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2018-07-26T20:00:57+02:00","dateModified":"2024-05-14T07:57:54+02:00","inLanguage":"en-US","commentCount":7,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#webpage"},"articleSection":"C++, C++, C++11"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#listItem","name":"C++ rules for special member functions"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#listItem","position":5,"name":"C++ rules for special member functions","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/","name":"C++ rules for special member functions","description":"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2018-07-26T20:00:57+02:00","dateModified":"2024-05-14T07:57:54+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"C++ rules for special member functions","og:description":"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.","og:url":"https:\/\/mariusbancila.ro\/blog\/2018\/07\/26\/cpp-special-member-function-rules\/","article:published_time":"2018-07-26T18:00:57+00:00","article:modified_time":"2024-05-14T05:57:54+00:00","twitter:card":"summary","twitter:title":"C++ rules for special member functions","twitter:description":"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user."},"aioseo_meta_data":{"post_id":"3081","title":null,"description":"A drill down of the C++ special member functions generated by the compiler based on what members are defined by the user.","keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6369777e55617","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:04:51","updated":"2025-12-12 07:50:13","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":7,"uagb_excerpt":"C++ has several special member functions that are defined by the compiler even if not defined by the user. These special member functions are the default constructor, the copy constructor, the copy assignment operator, the move constructor, the move assignment operator, and the destructor. However, there are many rules for what is defined and in&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++11<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">C++11<\/span>"]}},"comment_count":"7","relative_dates":{"created":"Posted 8 years ago","modified":"Updated 2 years ago"},"absolute_dates":{"created":"Posted on July 26, 2018","modified":"Updated on May 14, 2024"},"absolute_dates_time":{"created":"Posted on July 26, 2018 8:00 pm","modified":"Updated on May 14, 2024 7:57 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-NH","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=3081"}],"version-history":[{"count":19,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3081\/revisions"}],"predecessor-version":[{"id":4731,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3081\/revisions\/4731"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=3081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=3081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=3081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}