{"id":4332,"date":"2014-03-30T09:54:21","date_gmt":"2014-03-30T09:54:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dynamic-instantiation-in-c-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:54:21","modified_gmt":"2014-03-30T09:54:21","slug":"dynamic-instantiation-in-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dynamic-instantiation-in-c-collection-of-common-programming-errors\/","title":{"rendered":"Dynamic instantiation in C++-Collection of common programming errors"},"content":{"rendered":"<p>I want my code to be extensible, in a way where at runtime I create the objects.<\/p>\n<p>For example, let&#8217;s say I have a Grocery class which has an array of fruits and I want to fill this array of fruits with objects which derives from fruits.<\/p>\n<pre><code>class Fruit{\n\n};\n\nclass Grocery{\n\n    std::vector m_fruits;\n};\n\nclass Apple: Fruit{\n\n};\n\nclass Pineapple: Fruit{\n\n};\n<\/code><\/pre>\n<p>Now at runtime I want my Grocery class vector <code>m_fruits<\/code> to be filled with class objects of Apple and Pineapple. So is it possible in some way.<\/p>\n<p>if I add another fruit as strawberry in future, its object will be created and added to the vector of Grocery dynamically without changing the implementation of Grocery class?<\/p>\n<p>Code help will be appreciated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want my code to be extensible, in a way where at runtime I create the objects. For example, let&#8217;s say I have a Grocery class which has an array of fruits and I want to fill this array of fruits with objects which derives from fruits. class Fruit{ }; class Grocery{ std::vector m_fruits; }; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4332","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4332"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4332\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}