D
diadia
when i write two classes as follow .
compiler tell me that i can't access private number from other class
but if types of two classes are the same it don't have error message ? why?
class schema
{
private:
string name;
int age;
public:
schema(string n,int a):name(n),age(a){}
};
class data
{
private:
string str;
int num;
public:
data(int n,string s):num(n),str(s){}
data(){};
//error ! access private member from other class
void gets(const schema &s){str = s.name ; num = s.age ;}
// ok it can work,but why? it's also private member
void getd(const data &s) { str = s.str ; num = s.num;}
void put(){cout<<str<<num;}
};
compiler tell me that i can't access private number from other class
but if types of two classes are the same it don't have error message ? why?
class schema
{
private:
string name;
int age;
public:
schema(string n,int a):name(n),age(a){}
};
class data
{
private:
string str;
int num;
public:
data(int n,string s):num(n),str(s){}
data(){};
//error ! access private member from other class
void gets(const schema &s){str = s.name ; num = s.age ;}
// ok it can work,but why? it's also private member
void getd(const data &s) { str = s.str ; num = s.num;}
void put(){cout<<str<<num;}
};