Does public and private have any influence on the memory layout of an object?

Viewed 3824

This is a followup to another question of mine: What is the optimal order of members in a class?

Does it change anything (except visibility) if I organize the members in such a way that public, protected and private take turns?

class Example
{
public:
  SomeClass m_sc; 
protected:
  char m_ac[32];      
  SomeClass * m_scp;
private:
  char * m_name;
public:
  int m_i1;
  int m_i2;
  bool m_b1;
  bool m_b2;
private:
  bool m_b3;
};

Is there a difference between this class and a class where I make all members public at runtime? I want to follow the rule of ordering the types from large to small (if readability is not seriously harmed).

I assume that it does not affect the compiled program at all, just like const is only checked during compilation. Is this correct?

2 Answers
Related