Why can I access private variables in the copy constructor?
问题 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: Field::Field(const Field& f) { pFirst = new T[f.capacity()]; pLast = pFirst + (f.pLast - f.pFirst); pEnd = pFirst + (f.pEnd - f.pFirst); std::copy(f.pFirst, f.pLast, pFirst); } My declaration: private: T *pFirst,*pLast,*pEnd; 回答1: IMHO, existing answers do a poor job explaining the "Why" of this - focusing too much on reiterating what