The origin of the problem: I am looking at the new version of "C Programming Thought", I saw that the copy constructor is roughly like this, very unexpected: Class A {Int n; // Private NPublic: A (Const A & A : n (an) {} // Why can I call an AN, n is clearly private} In addition, there is such a problem when it is overloaded = operator.
The answer later is: private is an access between heterogeneousness, rather than limiting access to different objects, only SmallTalk is restricted along with different objects of different objects.
This will clearly understand why the copy constructor can copy another object according to a complete copy of an object.
But this seems to be a bit wrong, which means that a class in C is his own friend, and there is a complete transparent between the different objects of the same type, an object can access another member of the other, including private. Is this unreasonable?
For example, (the following example is not easy): Class Men {Private: Chicken JJ; public: Operation (Men x);} We define a man's class, one of the men's characteristics is a small chicken, this should It is private, otherwise it is unimaginable. Below we assume that there are two men: men a, b; a. Operation (b); if there is such a sentence in the definition of "operation": Men :: Operation (Men x) {x.jj = null;}; It doesn't seem to be very good, even if the two are men, how can they take the children's chicks, unless it is a love. . . -_-!
So I am more agreeable with SMALLTALK's approach, defining the private belonging to the object, not the class. Then the problem is coming, if it is limited to the object, that is, the object that is passed, even the similar object, can not access its private member, how is the copy constructor implementation?
My thoughts are: If you design, you should understand private, public and copy constructs: When you copy an object, you can only create a new object creation based on the disclosed part of the copy object. If a private member can get and assign a value through a disclosure method of the object; if there is no way to obtain a private member, it should be assigned an initial value.
Discussion on the problem of problems on the water in the water.
In addition, further YY, suppose is a woman's class, assuming men set the woman to the Friend class, which seems not very good, the woman can visit the men's winter winter. . . So you should set a function (behavior) of the woman to Friend. In the process, the woman can visit the men's winter and winter, which seems to be more reasonable. . . (Too e, do not continue: p)