Write while thinking
Explore the subclass object assigned to the parent class object #include <iostream>
using namespace Std;
Class A
{
Public:
int A;
int b;
};
Class B:public A
{
Public:
int A;
int b;
void Func ()
{
A::A = 100;//The control of the inherited part, by the way of the domain name, can only be done in the class
A::B = 200;
}
};
int main (void)
{
cout << sizeof (A) << Endl;
cout << sizeof (B) << Endl;
These two lines of code show that two data members in a and two data members in B are not related
A A;
b b;
A = b;
cout << a.a << endl << a.b << Endl;
B.func ();
A = b;
cout << a.a << endl << a.b << Endl;
The comparison between the two is very strong,
/*
As you can see, the assignment of a subclass to a parent class is actually a partial assignment from the parent class in the subclass object to the parent class object ...
Think about it, such a assignment, as if it is simply a function of the data members, as if there is no relationship with the member functions.
It is true that we can modify the data members inherited from the parent class in the subclass, and the member functions of the parent class. I don't think so.
Make any changes to it,
So
There is a relationship between the assignment of a subclass to a parent object, which is only a more data member.
There is the handover of authority.
*/
B. (a::a) a= 1000; Attempts to manipulate the members of a parent class in a subclass by way of a domain name are not possible outside of subclasses. Must be in the class
return 0;
}
/*
See a word "truncate", the modifier subclass is very good for the parent class object assignment.
That is, a new member object of a subclass is truncated when it assigns a value to the parent class object. Only the parent class member is left ...
*/
I'm happy to share what I want when I write the code.