Topic: access to class private data


Author: vinharUNSPAM@optusnetUNSPAM.com.au ("Vince Morgan")
Date: Fri, 1 Apr 2005 03:47:41 GMT
Raw View
"Andy White" <brighamandrew@msn.com> wrote in message
news:ZO%2e.7039$eK6.1281@fe02.lga...
> If I have a class:
>
> class IntArray
> {
>     public:
>         //.... Various members
>     private:
>         int _size;
>         //.. other data members
> };
>
> I have a copy constructor:
>
> IntArray::IntArray(const IntArray &rhs)

I think the line above should give you a clue :)
Think about that line for a few moments.

> {
>     _size = rhs._size;    //I don't understand why this works since rhs is
> another object and
>                                   //_size is private. How can the private
> data of this object be accessed?
>     //other code
> }
>
>

HTH
Vince Morgan


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]