§1 Talk from the object
Painting: Recently, the company came again with a newcomer and was assigned to our group. As a result, I learned that she had to learn C, didn't get in touch with C , so our head - SolmyR - gave me the training of her task. In this way, our group has a MM, and other groups are so embarrassed ^ _ ^ 喔, I almost forgot to introduce, the new call is Young ...
Everyday work is still the same, it seems that there is no change, occasionally look at my new apprentice young, she seems to always read the book, it seems that I haven't integrated with you, after all, I am coming for a day.
Well, hit hard, I still follow the practice, open Outlook, and receive the email.
Suddenly, MSN jumped out of a message "Weily, is there a time after collecting work today? If you have time, you will eat it together, I invite ^ _ ^.
Oh, I am dinner. So, I will reply immediately: "Okay :)"
......
After the collection, I went to eat with Young. On the road, young has been asking me how long I have learned C , I also feel that this meal is a purpose ...
"Master, when did you give me a guide C ?" Young finally said the purpose of the guest.
"I? This ... is right, Solmyr calls you" THE C Programming Language "?" I deliberately pulled the topic.
"Ah? I am still looking at it, but you are the master of SolmyR gave me, you don't want to push away my mission, otherwise, this meal ..."
I can't see it, she is so savvy. Also move out of the name of SolmyR to threaten me, this is enough.
"So your idea is?"
"Of course, you gave me a class" Young makes her most attractive smile, but I always feel that this smile is a bit evil.
"That is still to answer, I just asked questions, how is the 'Bible'?"
"I just saw the book, I feel that many things are difficult to understand, even I have to find Chinese version, I don't understand, have a lot of questions, so I have to give me a guide. And, I also I have seen some evaluations and discussions online. It seems that many people say that this book is not suitable for entry ... "
"Indeed, Bjarne said herself, this is really less suitable for beginners, but if you want to learn C , then this book must be seen. So, I will put my own understanding and experience. Stepline tell you this, give you a general impression of C , then you should see this book, you should have a little experience. "
"Okay, I will see it. Either we will start the first lesson now." Young seems to be a bit can't wait.
"You should have heard of object-oriented, that is, Object-Oriented, referred to as oo."
"Well, this I know .c is an object-oriented high-end language. But I only know these" Young changed a smile, it seems very humble.
"So, we will start from the object. Of course, due to the relationship, I can't explain the object-oriented technology, and I have not reached the realm of SolmyR, so I will tell you. These things can only be introduced, that is, entry nature. "" Ok, I will go to read the book, I want to have more detailed content on the book. "
"Well, this attitude is very good, praise first. Hey, before the beginning, I will ask you a question, do you know how much 'object', is the concept of 'object'?"
"Object, I think it is the same thing, it can be specific or abstract."
"I can say that I can say this. In fact, C Class, that is, class is equivalent to the type of C, like INT, CHAR, etc., the concept of its representative, and the object is an instance (instance) A simple example, 'book' is a Class, and a "The C Programming Language is an instance of this class."
"Oh, I know some. You continue to speak"
I originally wanted to use her time to eat à la carte, but I just took a dish with chopsticks, I haven't sent it to my mouth, she understands, pity I can only put the dish into the bowl, wait for the next time.
"C has the purpose of this concept, is to provide the programmer a tool for creating their own type, but also makes these user-defined types and C built-in types. So, a class It is a user-defined type. Moreover, Class can implement data packages and information hidden, so that users who use this class do not have to understand this Class design details, just understand the function and method of use of its public interface. Yes. I remember Solmyr and I said, you have learned C, then should I use the Struct in C? "
"Well, this is used. In the case of the data structure, use the data structure such as this list of single-link tables."
"C Class, in a sense, it is the Struct in C, which is the difference, mainly members in the class defaults to private (Private), and the involves is public, this is public, this It is the main difference. Of course, this difference can be unified by changing access restrictions. These specific, you can see from the book. Let's start with an example. Remember the stack in the data structure (Stack) Does this concept? "
"Remember," Filo). "YOUNG seems to be very proud.
"Well. If I want to build a stack of storage, INT, what do you need?"
"Need an array for storing variables."
"Array? If you use the array to build a stack, there is a size limit. About this problem, let us first consider it. So I ask you again, generally for the stack, what is commonly used?"
"In the stack and out of the stack, Push and POP" Young once again exposed a smile.
"Well, it seems that your data structure is still not bad ...", I deliberately drag the last sound, it seems to be ironic, waiting for her to felt this, I immediately asked: "These things, That is, the array and Push, POP two operations are closely related? "" It should be. "
"No, it is sure! Remember, as a programmer must have a certain confidence in things that you have clearly and mastered!"
"understood……"
"So if you can reflect these things in C."
"It doesn't seem to be. I wrote two functions of Push and POP when I wrote it. In addition, it was built an array, but I can't see it directly."
"Yes! But if you consider this stack with C Class, it is completely different. The array you said is the data member of this class, while Push and POP operations are two members of this class. MEMBER FUNCTION, this class is approximately like this ... "
I turned to be prepared to find paper and pen, young has already passed the book and the pen, it seems that she has had a premeditude. I took the book and the pen and wrote:
Class IntStack {public: ... bool push (int data); int pop (); ... private: ... int _stack [max];
"This is the general structure of the integer stack, which I just mentioned. Of course, we have ignored many details here, which is better than constructor, destructor, copy constructor, etc., and a stack uses an array to achieve Not well, after these details, we will pay attention to. C actually have a lot of features, when we speak generics and templates, we can make this stack into a template class. Oh, you want There are still many things, a little bit. "
"Hey, I know, what do you want to say is 'The road behind it is very long,'?" Young winking his eyes, smiling.
"How do you know that I want to say this?"
"This is? The planet knows! Hehe ..."
faint. Indeed, I often say that familiar with me knows, but young is coming, before eating this meal, if I said, I will probably not more than five sentences, how can she know?
Oops, bad, the rice hasn't eaten yet. When I thought of this, I found out that several vegetables on the table were basically "eliminated". It seems that my dinner is still not resolved. And she seems to have a good look. I finally understood the pain when Solmyr took Pisces.
Note: 1. Refer to Bjarne Stroustrup "The C Programming Language" 2. My C level is not high, the purpose of writing this small piece of art is to help me in order to help me. Systemically re-learn C ^ _ ^