Why can I access private variables in the copy constructor?

前端 未结 5 921
梦谈多话
梦谈多话 2020-11-29 16:27

I have learned that I can never access a private variable, only with a get-function in the class. But then why can I access it in the copy constructor?

Example:

5条回答
  •  佛祖请我去吃肉
    2020-11-29 16:43

    Copy constructor is class' member function and as such has access to class' data members, even those declared as 'private'.

提交回复
热议问题