can you access private member variables across class instances?

后端 未结 2 1798
旧巷少年郎
旧巷少年郎 2020-12-04 02:17

I didn\'t think it was possible, but if you have two instances of the same class, are you allowed to access one\'s private members from the other?

Is this why you ca

2条回答
  •  抹茶落季
    2020-12-04 03:12

    Yes, any code within a class can access private data in any instance of the class.

    This breaks encapsulation if you think of the unit of encapsulation as the object. C++ doesn't think of it that way; it thinks of encapsulation in terms of the class.

提交回复
热议问题