C ++ learning feelings

zhaozj2021-02-16  95

Original author name ROBIndy

Many people make learning C language as learning VC, I have gone through such a detour. It is still going back to learn the C language itself after learning for a long time VC. So where is it to learn C ? The C language introduces two large new things for C language, one is object-oriented (the specific class is class), and the template technology (template programming or generic program is coming in very popular technology, in C # Although there is no support for generic programming, it is believed that this feature will be added in the future), and the template is a complicated part of C , but as a real C programmer, this is important. Especially the mastery of the C standard library is particularly important. Don't just start the various wizards and designers in the VC when you start. Because many of the code that relies on the development environment will make us confused, it is not conducive to our learning C language itself. My suggestion is to generate an empty console project and then add a file to it. The following is a simple console program: //robindy/list.cpp#include #include using namespace std; int main () {list coll; for (char c = 'a'; C <= 'z'; c) {COLL.PUSH_BACK (C);} list :: const_iterator pos; for (POS = Coll.begin (); POS! = coll.eGin (); POS) { Cout << * pOS << ';} cout << Endl; Return 0;} For the Using Namespace STD; the interpretation of the Namespace, is a variety of visible ranges of the identifier. All identifiers in the C standard library are defined in a namespace called STD. Due to the NameSpace concept, there can be three options when using any identifier of the C standard library, you can specify the identifier. For example std :: ostream rather than ostream. The full statement is as follows: std :: cout << std :: hex << 3.4 << std :: end1; 2, using the use of keywords. Using std :: cout; using std :: endl; the above program can be written as cout << std :: hex << 3.4 << endl; 3, the most convenient is to use the use of namespace std; this namespace STD defined all the identity defined in the STD Valid (exposure). It seems that they are declared as global variables. Then, the above statement can be written as follows: cout << Hex << 3.4 << endl; this program uses the standard template library, print characters a ~ z on the screen, where the MAIN function is marked only two is the C Standards Committee Accepted, only the following two ways are compliant with C standards, which is portable.

That is: int main () {} and int main (int Argc, char * argv []) {} C defines an implicit return 0 at the end of Main (); but must be explicitly written in VC. Scriptures. You can compile RETURN in the BCB. The container in STL is used in this program: linked list. First insert 26 letters into the list, then from the traversal chain table, output characters. I don't recommend that beginners start from the template library at the beginning, but I suggested learning template libraries. If we should be familiar with COUT and CIN usage (located in iostream), reducing Printf and Scanf in the vintage C function library. The advantage from the console is to avoid other code generated by tools that we understand the VC center, the entire program process is clear. A big difficult problem with the novice learning VC is to engage the process of the entire program (from that statement to execute, then exit from that statement. MFC has made too many packages, covering the truth, ^ _ ^). We can quickly learn a lot of new features in the C language through the console. Such encapsulation, inheritance and polymorphism. Through this period of learning, you must be able to grasp three things: C keywords, syntax (focus is related to object-oriented, and template), C standard library (know how to use it, you must thoroughly need a lot of time and energy ). As for Dongdong related to the interface (a large part of the MFC is related to the interface, I think the MFC is very bloated and bored! I have seen the program written by MFC before, there is a "garbage" feel.) Test: Write a console program that reflects the inheritance of the class, the function overload, dynamic polymorphism (through virtual function implementation), data package, C standard library. If you can easily get it, congratulations, you have passed the C language. However, C is really a complex stuff, which has a variety of strange syntax, if there is no three, five years of skill, don't say that you know C . ^ _ ^. Recommended book "Thinking In C " (with energy, you can directly read the original version) "Essential C " Originally I plan to continue to talk about how to enter C world, but ponder, I don't want to solve a problem first: Why do you want to learn? C ? I think it is interested in learning new things in the software development. In addition to the livelihood, learning new things should be guided by interest. So I will open my personal pair of C , I want to build C confidence and interest for you. At the beginning, I learned that I learned C is: I can't waste halfway! At first, it was an interest-driven. Later, it was a livelihood, and finally returned to interest. After all, I have been having fun, this is enough. Solving motive problems before learning a new thing. Just like a murder, if it is just sudden rise, then after trying, it is no sense of accomplishment. The revolutionary martyrs have made a good example for us. Even if we encounter too many confusion and pain on the road to study C , we have made efforts to our beliefs, we know what you are doing, know yourself in pursuit what.

What kind of development is C suitable for? C is a large language widely used in industrial software development. It has high complexity and ability to solve problems. C is not only a very value in development, but also has a high value in the academic world. Articles about C should be able to describe the voyage of the smoke. C world-class classic books are also countless. However, the development language is so prosperous, even Microsoft has also launched a new development language C #. A undeniable reality is that in the low-order programming field, C squeezed C and also suffering from the strong rebound of C, it is said that it is said to be a Microsoft operating system source code, many of which is a C language. In the high-order programming field, Java and C # are constantly eating C sites. Perhaps Java and C # frenzy will eventually force C to return to this bite - returning to it with fundamental advantages: low-level system program design, high-level high-performance application design, embedded program design, general program design, numerical scientific calculations, etc. . As such, I think this is not a good thing. The high performance and large-scale numerical calculations required by the power system software are being good at C . For Nanrui and Luneng I have contacted, many software involved in power systems such as PAS, etc., are developed with C . Develop this position in the power system software, C is very useful. C attracts such intellectual investment, so that excellent works in this field, including heavyweight software products, libraries, and books, etc. On the Parent Bjarne Stroustrustroup of C , there is some (all or most) systems, applications, and libraries written in C . Here are some examples (from glory website): o Adobe Systems: All major applications are developed using C , such as Photoshop & ImageReady, Illustrator, and Acrobat, etc. O Maya: Does the "Spider Man", "Refers to the Rings King"? What software is used? That's right, it is Maya. o Amazon.com: Develop large e-commerce software using C . o Apple: Some important "parts" are written in C . o AT & T: The largest telecommunications technology provider in the United States, main products are developed in C . o Google: Web Search Engine is written in C . o IBM: OS / 400. o Microsoft: The following products are mainly written primarily in C (Visual C ): o Windows XP Windows NT: NT4, 2000 Windows 9x: 95,98, Me Microsoft Office: Word, Excel, Access, PowerPoint, Outlook Internet Explorer, including Outlook Express Visual Studio: Visual C , Visual Basic, Visual FoxPro .NET Framework class library is written in C #, but the C # compiler itself is written using C .

Exchange SQL Server FrontPage Project All games ... O Kde: K Desktop Environment (Linux). o Symbian OS: One of the most popular cellular phone OS. Many newcomers are particularly prone to doubts, confused. I feel that I have learned this thing, I spent so much time, will it be used? This kind of thought is very common. In some forums, they often see the pros and disadvantages of each language, knowing that the language they have learned is good, but if they stay at this level, they are not used. Any language is just a tool. It is important to use the tool! As far as my personal experience, people who really develop in the industry are willing to use mature, to complete their work. And novices like to use some new technologies to do development, and like to pursue novel (easy to see from the interface, the flower green interface is mostly from the newcomer). In fact, there are some efficient methods that may be low, scalable, and maintenance methods to solve the problem is not the development of the developer. They are just working in work. But as a truly self-motivated developer, we should use more elegant and efficient programming technology, which is a good habit we gradually become "big cows". Old is staying in place, it is easy to be eliminated. This is especially true in software development. Whether it is a student, or a first-line developer, I don't think I can't produce a "book reading enough"! I sometimes like to turn out the book I have seen, and I can always understand some new things every time. This is something like C language book, and I think I haven't been very good. why? Because I think the learning language is only the first step in the newcomer to enter the software to develop "Hell". The language is far less than enough. It is also necessary to learn related libraries (C of course first choice first learning C standard libraries), Related platform technologies (such as .NET), more far, and exercise the analysis, summary ability of the target problem. Before working, the technical route is the master, after work, most of the programmers will be around the company's technology route. So, I have time now, you can learn some you are interested. If you want to engage in software development, especially the development of power system software, learn C will not disappoint us. When we entered the front door of C , then after a dark road, then from the back door to the top of the light, we will feel the feeling of "a small mountain". Recommended books: "Programming Master Proverbs" Liang Yixin (with Super Solitae should know the first book written by ^ _ ^), which is worth reading. In this book, Liang tells us that learning is to be patient, we must resist "loneliness", take your own way, let others go to "say"! Recently, I am busy. It turns out that the topic is about the details of some specific C languages, but it still can't take a large period of time. So now I can only talk about some stories about C . C originates from the C language, remember to learn the time to learn C language for a long time (that is a happy and full time), but now learn C , not on the basis of C, if this is, we think, we are It is not good to play C .

Therefore, C is never upgraded or expanded, we should learn C as a new language (C parent Bjarne Stroustrup ". Write programs first hope that the program can be executed correctly, followed by the efficiency to be accepted, and again is easy to maintain. C is a difficult language. C provides too much option, and uses C to write programs to have four think modes: process, object-oriented and generic. We use a language to write a program, which does not mean that use the language itself. In other words, we are more when we use the library in writing programs. For example, MFC, STL, ATL, VCL, and more. Among them, C is used to write a beautiful, excellent performance, simple code, easy-to-maintain code, and push the C standard library. STL has a strict requirement for efficiency, and the procedure written by STL is simple and beautiful (I specially posted a post on several integers for some integer. In fact, the purpose is to showcase STL's simple and elegant). Once you are used to using generic thinking, we can fully understand the beauty of the template! For numerical calculations, the C standard library can fully meet the requirements of the modern service and commercial calculations on data and information. I think that I have a good language is to practice. That is, "Write"! "Accumulation of Engineering Experience" is very important for programmers that have been developed! Only in constant accumulation, we can gradually understand some of the things behind the C language. For this point, there is no rookie with a lot of program code writing experience, or you can use "Effective C " first with some experience. "Effective C " is a good book! . Meyers' book is absolutely worth reading, and Meyers can say today's C community has a technical expert. Recommended website: www.royaloo.com The following text should be doodled last year, mainly about dynamic memory allocation, here to look at it, think it is too light. Because the memory is the "sports field" running, the degree of understanding of the site will directly affect the fluency and stability of our program run. C provides operator New to allocate memory on the heap, operator delete to release memory. In some cases, we need to better control the allocation and release of memory. Many programs create and release a large number of important objects, such as Tree Nodes, Linked Lists Links, Points, Lines, Messages, etc. Using universal memory distributors such as New and Delete to make these object allocation and release sometimes dominate The runtime and memory requirements of the program. Two-aspect of factors: General Memory Distribution Operations The cost of operation and space consumption and memory fragments caused by different object sizes. Class Use custom memory splitters will speed up the speed of execution of the simulator, compiler, and similar programs. Exception a case where better memory control is: a program that needs to operate for a long period of time for a limited resource. Real-time systems often require minimal cost to obtain guaranteed expected memory. This also leads to better memory control. In general, these programs avoid using dynamic memory allocation, and use special purpose memory distributors to manage limited resources. In addition, there are also cases where the hardware or system requirements need to be placed in the specified memory location. This also needs customized memory management (implemented by overloading New).

In C Release 2.0, in order to meet the above needs, the memory management mechanism has made corresponding modifications. Mainly introduced Operator New [] and Operator Delete []. The first parameter of the Scope for Operator New Functions Operator Range (Scope) :: Operator New Global Class-Name :: Operator New Class Operator New must be type size_t (in STDDEF. The type defined in H), the return type is void *. When allocating an built-in type object, the class object of the user-defined new operator function is not included, and the global new operator function is used when any type of array is used. When the NEW operator is customized in the class, the NEW operator of the class is called when the memory of the class object is assigned. As follows: #include #include class Blanks {public: Blanks () {} void * operator new (size_t stAllocateBlock, char chInit);}; void * Blanks :: operator new (size_t stAllocateBlock, char chInit) {void * pvTemp = malloc (stallocateblock); if (pvTemp! = 0) MEMSET (PVTEMP, Chinit, StallocateBlock); Return PvTemp;} int main () {blanks * a5 = new (0xa5) blanks; // Create object Blanks, and initial testing is 0xa5return A5! = 0;} The New operator can be overloaded, but Delete is not. Because when you need to release it, what we can get is a pointer. Moreover, this pointer may not be the original object type pointer (possibly a type conversion). In fact, when a pointer to a single memory is obtained using the NEW, there is an indicator (INDICATOR) before the slice memory, and the actual number of memory is recorded. When the DELETE is called, you can know the memory size you need to release. DEALLOCATING ARRAYS: Void f () {x * p1 = new x [10]; // ... delete [] x;} Why don't you use Delete [10] X; free memory? Bjarne Stroustrup said that this approach is easy to cause errors, and the task of the number of records is placed in the implementation of Delete. As for why C , the C Language COLLECTION is seen, "C Language Design and Evolution" (EN) Bjarne Stroustrup Machinery Industry Press (commonly known as: D & E) can get an answer. In addition, a smart pointer Auto_PTR is provided in the C standard library. This pointer can help us prevent "resource leakage when you are thrown out." However, the disadvantage is that the smart pointer cannot point to an array because its internal release memory is performed by delete instead of delete []. So, you can only use it to point to a single object. The template portion is a more difficult part in C , and it is also the charm of C . The following text is what I have seen before, and the body is not clear. Today, I finished taking it, as a unit introduced as a template.

Why use the template for other functions, such as Quicksort, in addition to the type, we generally have three solutions. 1. Repeat the function entity (C language approach) for each different type: INT * quicksort (int A []) {...} double * quicksort (double a []) {...} ... 2 There are two efficiency problems in terms of two efficiency problems using Object (Java practices) or void * shortcomings. 3, using macro pre-processing mechanism shortcomings: just stupid text replacement, and will not consider scope and type security. However, the application template can avoid these shortcomings, we can write: Templatet * Quicksort (T a []) {...} Benefits: The code is simple and elegant, all parameter types are replaced with T, truly implement the type irrelevant. Better type security, all types of checks are performed during the compile period, and the pointer is avoided. There is no inheritance, high efficiency. (1) There is no virtual function; (2) All all work is completed during the compile period and greatly improve the operational efficiency. Purpose: Tell the compiler how to make the best choice, and this selection is completed in the compile period. Mechanism of Template: Charge and Real Meters 1, Charge Basic Template: TemplateClass A {// (1) Void F (T1 A, T2 B);} Local Charge (Off): Template Class A {/ / (2) Void F (int A, t2 b);} or template> class a {// (3) Void f (t a, t b);} Global Specialization (Explicit Specialization): Template <> Class A {Void F (INT A, INT B); // (4)} Using Example: A * P1; // Will use (4) - global specialization a * p2; // will be used (3) - - Local specialization A * P3; // will use (2) - local specialization A * P4; // will be (1) - basic template - generate // A Advantages: By: Global Specialization -> Part Charge -> Basic Template, the selection and matching of this specialization order (overload analysis rule) is automatically carried out by the compiler without manual participation. Different implementations can be given according to different situations (such as different types, different conditions), resulting in more flexible targeted. The scalability of the program can be improved in response to any change. 2 Interpretation of T Const & F (T Const & A, T Const & B) {RETURN A B; // 1} INT G = f (1, 2); actually f (1, 2) The function to match is INT Const & F (Int Const &, Int Const &); how did this function come? Advantages: There is no need to provide a pair of angle brackets and inside, such as F (1, 2), with real parametric, we can write into f (1, 2). Template application 1, standard library (STL) - a template code standard library = algorithm container iterator such as List / 2, type independent (T) 3, trait and policy (1) Trait: Mainly used Many typedefs are specified, specifying.

转载请注明原文地址:https://www.9cbs.com/read-13632.html

New Post(0)