{"id":3411,"date":"2021-07-06T15:51:27","date_gmt":"2021-07-06T10:21:27","guid":{"rendered":"https:\/\/www.goseeko.com\/blog\/?p=3411"},"modified":"2026-01-16T11:42:35","modified_gmt":"2026-01-16T06:12:35","slug":"what-is-a-constructor","status":"publish","type":"post","link":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/","title":{"rendered":"What is a Constructor?"},"content":{"rendered":"\n<p>In C++, a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Constructor\" target=\"_blank\" rel=\"noreferrer noopener\">constructor<\/a> is a specific procedure that is called automatically when a class object is formed.<\/p>\n\n\n\n<p>A constructor is a specific sort of class member function that initialises the class&#8217;s objects. When an object (instance of a class) is created in C++, it is immediately invoke. Because it has no return type, it is a unique member function of the class.<\/p>\n\n\n\n<p>In object-oriented programming, a constructor is a particular method of a class or structure that initializes a newly formed object of that kind. The constructor is automatically invoke whenever an object is created.<\/p>\n\n\n\n<p>It is similar to an instance method in that it can be use to set the values of an object&#8217;s members to default or user-defined values. It normally has the same name as the class. A cons, however, is not a legitimate method because it does not have a return type, despite its resemblance. It initialise the object rather than performing a task by running code, and it cannot be static, final, abstract, or synchronised.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Constructors  in C++ (HINDI\/URDU)\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/THoaGMzVbek?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h2>\n\n\n\n<p>class NewClass { &nbsp; &nbsp; \/\/ The class<\/p>\n\n\n\n<p>&nbsp;&nbsp;public: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Access specifier<\/p>\n\n\n\n<p>NewClass() { &nbsp; &nbsp; \/\/ Constructor<\/p>\n\n\n\n<p>&nbsp;&nbsp; cout &lt;&lt; &#8220;This is a Blog!&#8221;;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>};<\/p>\n\n\n\n<p>int main() {<\/p>\n\n\n\n<p>&nbsp;&nbsp;NewClass myObj;&nbsp; &nbsp; \/\/ Create an object of NewClass (this will call the constructor)<\/p>\n\n\n\n<p>&nbsp;&nbsp;return 0;<\/p>\n\n\n\n<p>}&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Types <\/strong>&nbsp;of constructor<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Default <\/li>\n\n\n\n<li>Copy <\/li>\n\n\n\n<li>Parameterized <\/li>\n<\/ol>\n\n\n\n<p><strong>Interested in learning about similar topics? Here are a few hand-picked blogs for you!<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.goseeko.com\/blog\/what-is-a-computer-processor\" target=\"_blank\" rel=\"noreferrer noopener\">What is computer processor?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.goseeko.com\/blog\/what-is-recursion\" target=\"_blank\" rel=\"noreferrer noopener\">Describe recursion?<\/a> <a href=\"https:\/\/rescrutiny.comillaboard.gov.bd\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/rescrutiny.comillaboard.gov.bd\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.goseeko.com\/blog\/index.php\/2021\/05\/31\/what-is-an-osi-model\/\" target=\"_blank\" rel=\"noreferrer noopener\">What is OSI model?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.goseeko.com\/blog\/index.php\/2021\/05\/31\/what-is-cryptography\/\" target=\"_blank\" rel=\"noreferrer noopener\">Phenomena of cryptography?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.goseeko.com\/blog\/what-is-machine-learning\" target=\"_blank\" rel=\"noreferrer noopener\">What is machine learning?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In C++, a constructor is a specific procedure that is called automatically when a class object is formed.<\/p>\n","protected":false},"author":3,"featured_media":1177,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-science-software-engineering-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is a Constructor? - Goseeko blog<\/title>\n<meta name=\"description\" content=\"A constructor is similar to an instance method, it can be used to set the values of an object&#039;s members to default or user-defined values.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is a Constructor? - Goseeko blog\" \/>\n<meta property=\"og:description\" content=\"A constructor is similar to an instance method, it can be used to set the values of an object&#039;s members to default or user-defined values.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\" \/>\n<meta property=\"og:site_name\" content=\"Goseeko blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/goseeko\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-06T10:21:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-16T06:12:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"359\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Team Goseeko\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@goseeko\" \/>\n<meta name=\"twitter:site\" content=\"@goseeko\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Team Goseeko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\"},\"author\":{\"name\":\"Team Goseeko\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/7ec300cd01b6116501943af14d546bae\"},\"headline\":\"What is a Constructor?\",\"datePublished\":\"2021-07-06T10:21:27+00:00\",\"dateModified\":\"2026-01-16T06:12:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\"},\"wordCount\":281,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1\",\"articleSection\":[\"Computers\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\",\"url\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\",\"name\":\"What is a Constructor? - Goseeko blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1\",\"datePublished\":\"2021-07-06T10:21:27+00:00\",\"dateModified\":\"2026-01-16T06:12:35+00:00\",\"description\":\"A constructor is similar to an instance method, it can be used to set the values of an object's members to default or user-defined values.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1\",\"width\":640,\"height\":359},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.goseeko.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is a Constructor?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#website\",\"url\":\"https:\/\/www.goseeko.com\/blog\/\",\"name\":\"Goseeko blog\",\"description\":\"Learning beyond college, Students platform for life skills.\",\"publisher\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.goseeko.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#organization\",\"name\":\"Goseeko.com\",\"url\":\"https:\/\/www.goseeko.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i1.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/09\/GoSeeko_Stacked-logo-01.png?fit=2471%2C2471&ssl=1\",\"contentUrl\":\"https:\/\/i1.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/09\/GoSeeko_Stacked-logo-01.png?fit=2471%2C2471&ssl=1\",\"width\":2471,\"height\":2471,\"caption\":\"Goseeko.com\"},\"image\":{\"@id\":\"https:\/\/www.goseeko.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/goseeko\",\"https:\/\/x.com\/goseeko\",\"https:\/\/www.instagram.com\/goseeko\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/7ec300cd01b6116501943af14d546bae\",\"name\":\"Team Goseeko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Team Goseeko\"},\"url\":\"https:\/\/www.goseeko.com\/blog\/author\/team-goseeko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is a Constructor? - Goseeko blog","description":"A constructor is similar to an instance method, it can be used to set the values of an object's members to default or user-defined values.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/","og_locale":"en_US","og_type":"article","og_title":"What is a Constructor? - Goseeko blog","og_description":"A constructor is similar to an instance method, it can be used to set the values of an object's members to default or user-defined values.","og_url":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/","og_site_name":"Goseeko blog","article_publisher":"https:\/\/www.facebook.com\/goseeko","article_published_time":"2021-07-06T10:21:27+00:00","article_modified_time":"2026-01-16T06:12:35+00:00","og_image":[{"width":640,"height":359,"url":"https:\/\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg","type":"image\/jpeg"}],"author":"Team Goseeko","twitter_card":"summary_large_image","twitter_creator":"@goseeko","twitter_site":"@goseeko","twitter_misc":{"Written by":"Team Goseeko","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#article","isPartOf":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/"},"author":{"name":"Team Goseeko","@id":"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/7ec300cd01b6116501943af14d546bae"},"headline":"What is a Constructor?","datePublished":"2021-07-06T10:21:27+00:00","dateModified":"2026-01-16T06:12:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/"},"wordCount":281,"commentCount":0,"publisher":{"@id":"https:\/\/www.goseeko.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1","articleSection":["Computers"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/","url":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/","name":"What is a Constructor? - Goseeko blog","isPartOf":{"@id":"https:\/\/www.goseeko.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage"},"image":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1","datePublished":"2021-07-06T10:21:27+00:00","dateModified":"2026-01-16T06:12:35+00:00","description":"A constructor is similar to an instance method, it can be used to set the values of an object's members to default or user-defined values.","breadcrumb":{"@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#primaryimage","url":"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1","width":640,"height":359},{"@type":"BreadcrumbList","@id":"https:\/\/www.goseeko.com\/blog\/what-is-a-constructor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.goseeko.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is a Constructor?"}]},{"@type":"WebSite","@id":"https:\/\/www.goseeko.com\/blog\/#website","url":"https:\/\/www.goseeko.com\/blog\/","name":"Goseeko blog","description":"Learning beyond college, Students platform for life skills.","publisher":{"@id":"https:\/\/www.goseeko.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.goseeko.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.goseeko.com\/blog\/#organization","name":"Goseeko.com","url":"https:\/\/www.goseeko.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.goseeko.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/i1.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/09\/GoSeeko_Stacked-logo-01.png?fit=2471%2C2471&ssl=1","contentUrl":"https:\/\/i1.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/09\/GoSeeko_Stacked-logo-01.png?fit=2471%2C2471&ssl=1","width":2471,"height":2471,"caption":"Goseeko.com"},"image":{"@id":"https:\/\/www.goseeko.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/goseeko","https:\/\/x.com\/goseeko","https:\/\/www.instagram.com\/goseeko\/"]},{"@type":"Person","@id":"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/7ec300cd01b6116501943af14d546bae","name":"Team Goseeko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.goseeko.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Team Goseeko"},"url":"https:\/\/www.goseeko.com\/blog\/author\/team-goseeko\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.goseeko.com\/blog\/wp-content\/uploads\/2021\/05\/code-1076536_640.jpg?fit=640%2C359&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/posts\/3411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/comments?post=3411"}],"version-history":[{"count":2,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/posts\/3411\/revisions"}],"predecessor-version":[{"id":12858,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/posts\/3411\/revisions\/12858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/media\/1177"}],"wp:attachment":[{"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/media?parent=3411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/categories?post=3411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.goseeko.com\/blog\/wp-json\/wp\/v2\/tags?post=3411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}