How is access for private variables implemented in C++ under the hood?

前端 未结 2 1627
失恋的感觉
失恋的感觉 2021-01-11 11:27

How does the compiler control protection of variables in memory? Is there a tag bit associated with private variables inside the memory? How does it work?

2条回答
  •  自闭症患者
    2021-01-11 12:07

    It's the compiler's job to see that some members are private and disallow you from using them. They aren't any much different from other members after compilation.

    There is however an important aspect, in that data members aren't required to be laid out in memory in the order in which they appear in the class definition, but they are required to for variables with the same access level.

提交回复
热议问题