More predictional C ++ started from the position of predictional C ++

Source: Internet
Author: User

The ancient Greek philosopher Socrates taught students by asking questions-he guided the students with well-conceived questions, inspired them to draw conclusions from known ones, and made them realize how things they are learning interact with each other, how do these things relate to their existing knowledge. This teaching method is so famous that we call it the "Socrates Q & A" method today ". If we look at the problem from the perspective of students, the Socrates teaching method will guide us to think, help us to contact and apply existing knowledge to get new knowledge.

This book, like its predecessor, exceptional C ++ [suter00], draws on the Socrates teaching method. It assumes that you are currently in a field of C ++ product software development, guides you how to effectively use the standard C ++ language and its standard library in the form of "question/answer"-especially, how to Use the effective software engineering theory in modern c ++ to solve the problem. Most of these problems come from the experience I have accumulated when writing product-Level C ++ Code and are presented to you in the form of so-called "Questions" and "difficulties. The purpose of "Doubt" is to help you draw conclusions from the existing knowledge and the knowledge you just learned and show how they are correlated. "Difficulties" show you how to analyze C ++ design and programming topics-some are common topics, some are not common; some are simple topics, some of them are more esoteric; there are also some topics for discussion, because -- well, just because -- they are very interesting.

This book covers all aspects of C ++. But I didn't say it touched every detail of C ++-that would require more space-I mean, this book extracts a wide range of materials from the C ++ language and standard library components, and shows you how seemingly unrelated individuals are comprehensively utilized to form a novel solution to common problems. It also shows how seemingly unrelated parts of these materials are associated, even if you don't want them to be so associated, and how to deal with these associations. You will find the template and namespace, exceptions and inheritance, robust design and design patterns, generic program design and macro usage skills, and other content here-these contents are not piled up in disorder together, as a coherent clause, we will show you how these components interact with each other in modern c ++.

What is "more "?

More than tional C ++ started from the stop of predictional C ++. This book inherits the legacy of its predecessors: it provides new content, which is organized into short clauses to form Topic chapters. Readers of the previous book will find some familiar chapters and topics here, such as exception security, generic programming, and memory management technologies, but now they include new content. These two books overlap in terms of structure and subject rather than content.

What is the difference between more than tional C ++? This book particularly emphasizes generic programming technology and how to effectively use the C ++ standard library, and involves important technologies such as traits and predicates. There are several terms that further analyze the key points that should be kept in mind when using standard containers and algorithms-many of these points that I have not seen elsewhere. In addition, a new chapter and two appendices focus on optimization issues in single-line and multi-threaded environments-for software developers who write product-level code, these topics are of more practical value than ever before.

Most of the articles in this book were originally introduced in Internet and magazine columns, especially the gotw topic 31 to 62 of guru of the week, and I used C/C ++ users Journal, dr. dobb's journal, previous C ++ reports, and printed columns and articles written in other publications. Since the emergence of the original version, the content of this book has undergone a lot of revisions, additions, corrections and updates, so this book (together with it in www. gotw. CA) can be considered as the latest official version of the original materials.

You should know

I think you have learned the basic knowledge of C ++. If this is not the case, we recommend that you start with a good C ++ entry and conceptual book. You 'd better choose a classic big part book, for example, the C ++ programming language [stroustrup00] of Bjarne stroustrup, or the third edition of C ++ primer [lippman98] co-authored by Stan Lippman and Jos é e Lajoie. Then, be sure to select a book that guides the programming style, such as Scott Meyers's classic textbook C ++ package [meyers96] [meyers97]. I found that this set of books has a CD version [meyers99] based on a browser, which is very convenient and easy to use.

How to read this book

Each clause in this book is presented in the form of a puzzle or question with an introductory title, similar to the following:

Clause #: Question difficulty of the clause: x

The question and difficulty level of the terms indicate the difficulties you will face. Note that the difficulty level is my subjective evaluation. I just guess how difficult it is for most people to encounter each problem, therefore, you may find that a problem with difficulty 7 is easier for you than a problem with difficulty 5. Since writing exceptional C ++, I have received some e-mails from time to time, saying that "the clause is easier (difficult) than you said )". In the face of the same clause, different people think that "easier" or "more difficult" is natural. The difficulty level varies with people. For you, the actual difficulty of any clause depends on your knowledge and experience. It is easier or harder for others. However, in most cases, you will find that difficulty grading is a good empirical method, which guides you roughly the same as what you think.

You may plan to read the entire book from the beginning to the end. This is good, but not necessarily so. You may focus on all the terms in a chapter because you are particularly interested in the topics in that chapter. This is also good. Some of the terms in the book are called "short series". Because they involve related issues, you will see these terms marked by "one" and "two. Except for these "short series", other terms are independent. The terms of this book also contain a lot of cross-indexing. For some indexes, refer to predictional C ++. You can follow these indexes to jump to and read them at will. The only thing I want to tell you is that the "short series" is made to make them a group for continuous reading. In addition, you can choose how to read them.

Namespace, typename, URL reference, and other conventions

I have made many suggestions in this book, but I will not guide you to do things that I have never done myself. This includes what I did in my own sample code in the entire book. I will also follow the existing habits and modern style of programming, even if sometimes this will not bring about a fundamental difference in things.

In this regard, let's talk about namespace. In the code example in this book, if you see the using command within the file range in one example, after several pages or several clauses, another example shows the using command within the scope of a function. In fact, there is no deeper meaning, but it only indicates that in specific circumstances, this is reasonable, and I feel beautiful from an aesthetic point of view. For more information about namespaces, see section 40. When writing code, if you want to emphasize what I mean by the standard, I will use STD: to modify the standard library name. After this is established, I tend to use a name without modification.

Let's talk about the template parameter declaration. I often come across some people who think that writing a class without writing a typename is outdated, even if the two do not have functional differences, and the C ++ standard itself is also everywhere. It is purely for the sake of the writing style of code, and to emphasize that this book is about today's modern c ++, when declaring template parameters, I have also switched to using typename instead of class. The only exception is one of clause 33, where I directly reference the code in the standard-the standard uses class, and I will follow it.

Unless I explicitly call a piece of code as a "complete program", it is generally not. Remember that these examples are usually only code snippets or only part of the program, and they are not compiled in this way. To construct a complete program using the program snippets provided by me, you usually have to do some obvious addition work.

Finally, let's talk about the URL. Everything is changing on the Internet. In particular, things that you cannot control are changing. In this way, publishing a URL on printed books becomes a real pain: You don't have to wait for a book to lie on your desk for five years before it is delivered to a printing factory, those URLs may be out of date. In this book, when I reference other people's articles or websites, I use the URLs on my own website www. gotw. ca. I can control this website by myself. It only contains the redirection link pointing directly to the actual webpage. If you find that a link printed in this book is no longer available, please email me and I will update this link, point it to a new webpage location (if I can find the webpage again) or mark that the webpage no longer exists (if I cannot find the webpage ). Either way, the URL of the book will be up-to-date-even in today's Internet world, printing media is so difficult. Alas!

Thank you

I am very grateful to Bjarne stroustrup, editors of the series, Debbie Lafferty, Tyrrell albaugh, Chanda leary-coutu, Charles Leddy, Curt Johnson, and other members of the Addison-Wesley press, thank you for your assistance and perseverance in this project. It is hard to imagine that even better people can work together, and their enthusiasm and collaboration have completely achieved the goal I expected.

In addition, many experts who have reviewed this book are worthy of thanks and praise. They put forward profound insights and sharp criticism on many of the contents of this book without reservation, and these insights and criticisms are so insightful. It is precisely because of their efforts that the book in your hand is more complete, easier to understand, and more practical than the first draft. Special thanks (I would like to extend my order of comments for review) scott Meyers, Jan Christiaan van Winkel, Steve Dewhurst, Dennis mancl, Jim hyslop, Steve clamage, kevlin Henney, Andrew Koenig, Patrick McKillen, and some unknown reviewers. All the mistakes, negligence, and ambiguity left over from the book are because of me, not them.

Finally, I would like to dedicate all my gratitude to my family and friends, who have been with me during the writing and publishing of this book and at any other time.

Herb Sutter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.