{"id":4486,"date":"2014-03-30T11:30:42","date_gmt":"2014-03-30T11:30:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-can-i-access-a-derived-private-member-function-via-a-base-class-pointer-to-a-derived-object-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:42:27","modified_gmt":"2022-08-30T15:42:27","slug":"why-can-i-access-a-derived-private-member-function-via-a-base-class-pointer-to-a-derived-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-can-i-access-a-derived-private-member-function-via-a-base-class-pointer-to-a-derived-object-collection-of-common-programming-errors\/","title":{"rendered":"Why can I access a derived private member function via a base class pointer to a derived object?-Collection of common programming errors"},"content":{"rendered":"<p>Access modifiers, such as <code>public<\/code>, <code>private<\/code> and <code>protected<\/code> are only enforced during compilation. When you call the function through a pointer to the base class, the compiler doesn&#8217;t know that the pointer points to an instance of the derived class. According to the rules the compiler can infer from this expression, this call is valid.<\/p>\n<p>It is usually a semantic error to reduce the visibility of a member in a derived class. Modern programming languages such as Java and C# refuse to compile such code, because a member that is visible in the base class is always accessible in the derived class through a base pointer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Access modifiers, such as public, private and protected are only enforced during compilation. When you call the function through a pointer to the base class, the compiler doesn&#8217;t know that the pointer points to an instance of the derived class. According to the rules the compiler can infer from this expression, this call is valid. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[],"class_list":["post-4486","post","type-post","status-publish","format-standard","hentry","category-semantic","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4486","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=4486"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4486\/revisions"}],"predecessor-version":[{"id":8785,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4486\/revisions\/8785"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}