AP(
unixpr...@verizon.net) wrote:
> In item 13 (Lazy optimization / copy-on-write) we see following ctor :
>
> String::String( const String& other ): buf_(new char[other.len_]),
> len_(other.len_), used_(other.used_)
> { copy(other.buf_, other.buf_+used_, buf_); }
>
> Class is defined thus :
> class String
> {
> public:
> String(const String&);
> ....
> private:
> char* buf_;
> size_t len_;
> size_t used_;
> ....
> }
>
> Question : how does our ctor have access to her argument's private data ?
> The situation repeats on quite a few occasions in the book,
Because both are objects of type String. That's how access protection
works in C++. If it were any other way, objects with private data
members couldn't be coped without a public accessor for each private member.
--
Ian Collins