{"id":5315,"date":"2014-03-30T20:39:23","date_gmt":"2014-03-30T20:39:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-implementation-of-access-specifiers-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:39:23","modified_gmt":"2014-03-30T20:39:23","slug":"c-implementation-of-access-specifiers-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-implementation-of-access-specifiers-collection-of-common-programming-errors\/","title":{"rendered":"c++ implementation of access specifiers-Collection of common programming errors"},"content":{"rendered":"<p>What&#8217;s your source? I think it refers to how the objects are represented in memory, but it&#8217;s the compiler, not the run-time, that deals with access specifiers.<\/p>\n<p>In memory, a <code>class<\/code> <em>might<\/em> look the same as a <code>struct<\/code>, but to the compiler they do not.<\/p>\n<p>Also, the two don&#8217;t have to be equivalent even in memory (much like they are not equivalent for the compiler). The compiler can re-arrange the members, as long as it keeps those with no interleaving access specifiers grouped together. So, in memory,<\/p>\n<pre><code>class Object {  \npublic: \n   int i1; \n   int i2; \nprivate: \n   char i3; \n   int i4; \n};\n<\/code><\/pre>\n<p><em>could<\/em> theoretically be represented as<\/p>\n<pre><code>struct {\n   char i3;\n   int i4;\n   int i1;\n   int i2;\n}\n<\/code><\/pre>\n<p>Note that I&#8217;m only talking about the memory layout here. The <em>actual<\/em> <code>struct<\/code> equivalent of your class is:<\/p>\n<pre><code>struct Object {  \nprivate:\npublic: \n   int i1; \n   int i2; \nprivate: \n   char i3; \n   int i4; \n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s your source? I think it refers to how the objects are represented in memory, but it&#8217;s the compiler, not the run-time, that deals with access specifiers. In memory, a class might look the same as a struct, but to the compiler they do not. Also, the two don&#8217;t have to be equivalent even in [&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-5315","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5315","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=5315"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5315\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}