-
A String Class question
Hey all,
I'm probably missing something obvious, but why the HELL does this copy constructer work?
Code:
class StrType {
char *p;
int size;
public:
StrType(const StrType &o); // copy constructor
~StrType() { delete [] p; }
};
That's the class, here's the code:
Code:
StrType::StrType(const StrType &o)
{
size = o.size;
p = new char[size];
strcpy(p, o.p);
}
Now howcome the copy constructer above can access those private members of 'o'?
Thanks.
-
Because the copy constructor is a member function of the same class of that of 'o'
-
Because o is a StrType object. It has class scope in StrType. As long as its accessed within the class, its fine.
-
so any member function of class X can always access any and all private members of the same class type?
-
-