After a period of time with VC , I found that C did not learn anything. Basic can't be basically basically, really use it deeply.
Three objects need to be defined, one base class A, and two other A1, A2 derived from this base class. It is also the problem that doesn't have to use Virtual, and it is very simple, maybe not paying, perhaps, it is also as good as this time, I have forgotten it when I don't care, or I will start writing the program under Linux. I don't know when I can pay attention. Write a write, perhaps next time I can think of it quickly. In fact, try it out, isn't it?
Class a {clist
m_lspoint;
Virtual void addpoint ()
{
m_lspoint.add (cpoint (0,0));
}
Clist
M_Lspoint2;
Void addpoint2 ()
{
m_lspoint2.add (cpoint (0,0));
}
}
Class A1: Public A
{
void addpoint ()
{
m_lspoint.add (cpoint (1, 1));
}
Void addpoint2 ()
{
m_lspoint2.add (cpoint (1, 1));
}
}
The difference between the two addPoints in the base class A is a Virtual, one is not. The test code is as follows:
A1 * a1 = new A1; ((a *) a1) -> addpoint (); ((a *) a1) -> addpoint2 ();
Like the calling method of the above two functions, the list of M_Lspoint and M_Lspoint2 is finally found that the point in which it is not the same is (1, 1), and the point m_lspoint2 is (0, 0). In this regard, I feel as follows:
1.virtual modified is the virtual function, as the name suggests that the function of the base class will no longer be created from him. A AddPoint function. AddPoint2 does not use Virtual modification, although A-> addPoint2 () is not executed directly in directly call A1-> addPoint2 (), but can be converted to the ADDPOINT2 function that actually exists.
2. A1 derived from A, that is, A1 has all attributes of A, such as a student's class, student number attribute in A, including his homework score. To update the student's class or a student number, it is actually available only A class members (class, student number). If it is updated directly from A1 (ie together), it will inevitably generate errors. At this time, it is required to use the base class that does not use the Virtual keyword. The structure is as follows:
- Class | - Student - | | | - Student Students | Information | - Language Responsive | - Mathematics. . . 3. Virtual keywords often use when using VC, but often use this method when inheriting. such as
Void A1 :: Addpoint () {a :: addpoint (); m_lspoint.add (cpoint (0,0));
This method has become the same as that, the base class, the attribute (member) of the derived class is updated again. However, if the base class is not Virtual, it is useless. Think, if you are in A1 :: AddPoint2, it is not effective as in this way, add the function of the parent class. It is not effective to use this ((a *) this) -> addpoint2 (); also useless. I don't understand this. There are too many things I don't understand in the world. Ontraw, onpaint in the VC, is also Virtual, but does not invoke the function of the base class. According to 1 thinking, these functions of the base class do not have to be created, and the memory is saved. is it? Not?
gosh! I have been using MFC, I don't have to consider the structure, layout, and all according to the template under Microsoft cloth. It's really failure, and I have learned myself. The structure of the base class is really important. When doing similar above, of course, there are not only A1, but because the base class is defined too bad, it is written, but he is old employee. ,failure. I am using it, for a few interfaces, and even the base class written, it is also putted in the derived class (repeated requirement invalid). The so-called procedure for the object is really depressed.
This time, in Unix, there is only the above experience, learn Linux, UNIX, VI, there is a new thing, I have a power.
I. . . also. . . Live!