📄 ch01.htm
字号:
<p>C++ differs from other object-oriented languages in many ways. For instance, C++ is not a root-based language, nor does it operate on a runtime virtual machine. These differences significantly broaden the domains in which C++ can be used.</p><h3> <a name="Heading11"> Backward Compatibility with Legacy Systems</a></h3><p>The fact that legacy C code can be combined seamlessly with new C++ code is a major advantage. Migration from C to C++ does not force you to throw away good, functional C code. Many commercial frameworks, and even some components of the Standard Library itself, are built upon legacy C code that is wrapped in an object-oriented interface. </p><h3> <a name="Heading12"> Performance</a></h3><p>Interpreted languages allow easier code porting, albeit at the cost of significant performance overhead. C++, on the other hand, uses the compile and link model it inherited from C. One of the goals of C++ designers has been to keep it as efficient as possible; a compile-and-link model enables very efficient code generation and optimization. Another performance factor is the use of a garbage collector. This feature is handy and prevents some common programming bugs; however, garbage collected languages are disqualifies for time-critical application development, where determinacy is paramount. For that reason, C++ does not have a garbage collector.</p><h3> <a name="Heading13"> Object-Orientation and Other Useful Paradigms</a></h3><p>In addition to object-oriented programming, C++ supports other useful programming styles, including procedural programming, object-based programming, and generic programming -- making it a multi-paradigm, general-purpose programming language.</p><p></p><p> </p><h4> Procedural Programming</h4><p>Procedural programming is not very popular these days. However, there are some good reasons for C++ to support this style of programming, even today.</p><p><b> Gradual Migration of C Programmers To C++</b></p><p>C programmers who make their first steps in C++ are not forced to throw all their expertise away. Many primitives and fundamental concepts of C++ were inherited from C, including built-in operators and fundamental types, pointers, the notion of dynamic memory allocation, header files, preprocessor, and so on. As a transient phase, C programmers can still remain productive when the shift to C++ is made.</p><p><b>Bilingual Environments</b></p><p>C++ and C code can work together. Under certain conditions, this combination is synergetic and robust.</p><p><b>Machine-Generated Code</b></p><p>Many software tools and generators generate C code as an intermediate stage of application build. For example, SQL queries on most relational databases are translated into C code, which is in turn compiled and linked. There's not much point in forcing these generators to produce C++ code (although some do so) when the generated code is not going to be used by human programmers. Furthermore, many early C++ compilers were not really compilers in the true meaning of the word; they are better described as translators because they translated C++ code into intermediate C code that was later compiled and linked. In fact, any valid C++ programs can be translated directly into pure C code.</p><h3> <a name="Heading14">Object-Oriented Programming</a></h3><p>This is the most widely used style of programming in C++. The intent of this book is to deliver useful guidelines and rules of thumb for efficient, reliable, reusable, and easy to maintain object-oriented code. But there is no universal consensus as to what OO really is; the definitions vary among schools, languages, and users. There <i>is</i>, however, a consensus about a common denominator -- a combination of encapsulation, information hiding, polymorphism, dynamic binding, and inheritance. Some maintain that advanced object-oriented consists of generic programming support and multiple inheritance. These concepts will be discussed in depth in the chapters that follow.</p><h3> <a name="Heading15">Generic Programming</a></h3><p>Generic programming proceeds one step beyond object-oriented programming in pursuing reusability. Two important features of C++, templates and operator overloading, are the basis of generic programming. STL, a collection of generic algorithms and containers, is probably the most impressive manifestation of this paradigm.</p><h2> <a name="Heading16">Aim Of the Book</a></h2><p>This book is aimed at experienced C++ developers who seek a guide for enhancing their design and programming proficiency. It discloses facts and techniques and provides a knowledge base for advanced, Standard-compliant, and efficient use of C++. In addition, the book also explains the underlying mechanism behind the high-level features of the language, and it explains the philosophy behind the design and evolution of C++.</p><h2> <a name="Heading17"> Target Audience</a></h2><p>The target audience is intermediate and advanced level C++ developers who want to improve their proficiency by acquiring new programming techniques and design idioms. On top of adding many new features to the language, the standardization committee has deprecated several features and library components. In this book, readers who want to develop long lasting, future-proof C++ software can find a comprehensive list of deprecated features and their recommended alternatives.</p><h2> <a name="Heading18">Organization of the Book</a></h2><p><b>Chapter 2</b>, "Standard Briefing: The Latest Addenda to ANSI/ISO C++," presents some of the key terms that are used in the C++ Standard, and which are used extensively in this book. Following this, the recent changes and extensions to C++ are described. Finally, Chapter 2 gives an overview of the deprecated features that are listed in the Standard, and suggests standard-conforming replacements for them.</p><p><b>Chapter 3</b>, "Operator Overloading," explores the benefits as well as the potential problems of operator overloading. It discusses the restrictions that apply to operator overloading and explains how to use conversion operators.</p><p><b>Chapter 4</b>, "Special Member Functions: Default Constructor, Copy Constructor, Destructor, and Assignment Operator," explains the semantics of the special member functions and their role in class design. It also demonstrates several techniques and guidelines for an effective usage of these special member functions. </p><p><b>Chapter 5</b>, "Object-Oriented Programming and Design," provides a brief survey of the various programming styles that are supported by C++, focusing on the principles of object-oriented design and programming.</p><p><b>Chapter 6</b>, "Exception Handling," first describes traditional error handling methods and their disadvantages, and then presents standard exception handling. A brief historical account of the design of exception handling is provided and, finally, exception handling-related performance issues are discussed.</p><p><b>Chapter 7</b>, "Runtime Type Information," discusses the three components of runtime type information (RTTI), namely <tt>typeid</tt>, <tt>dynamic_cast</tt> and class <tt>type_info</tt>. In addition, it explains when the use of RTTI is necessary. Finally, it discusses the performance overhead associated with runtime type information.</p><p><b>Chapter 8</b>, "Namespaces," elucidates the rationale behind the addition of namespaces to the language and the problems that namespaces solve. Then it demonstrates how namespaces are used in practice, and how they interact with other language features.</p><p><b>Chapter 9</b>, "Templates," discusses various aspects of designing and implementing templates, including class templates, function templates, and template issues that are of special concern (such as pointers to members, virtual member functions within a template class, inheritance relations, and explicit instantiations).</p><p><b>Chapter 10</b>, "STL and Generic Programming," is an introduction to the Standard Template Library and to generic programming in general. It discusses the principles of generic programming, focusing on STL as an exemplary framework of generic programming. This chapter also demonstrates the use of STL components: containers, algorithms, iterators, allocators, adapters, binders, and function objects. The most widely used STL components, <tt>std::vector</tt> and <tt>std::string</tt>, are explored in detail.</p><p><b>Chapter 11</b>, "Memory Management," explains the memory model of C++. It describes the three types of data storage: static, automatic, and free store. This chapter also delves into the semantics of operators <tt>new</tt> and <tt>delete and their underlying implementation</tt>. In addition, it demonstrates the use of advanced memory management techniques and guides you in avoiding common memory-related errors.</p><p><b>Chapter 12</b>, "Optimizing Your Code," is dedicated to code optimization. It provides useful guidelines and tips for writing more efficient code, and it proceeds toward more aggressive optimization techniques for minimizing space and accelerating runtime speed.</p><p><b>Chapter 13</b>, "C Language Compatibility Issues," demonstrates how to migrate from C to C++ and, in particular, how to migrate from procedural programming to object-orientation. It lists the differences between the C subset of C++ and ISO C. Finally, it delves into the underlying representation of C++ objects in memory and their compatibility with C structs.</p><p><b>Chapter 14</b>, "Concluding Remarks and Future Directions," seals this book. It describes the principles and guidelines in the design and evolution of C++ throughout the last two decades, and compares it to the evolution of other, less successful programming languages. Then it lists features that almost made it into the Standard. Next, it discusses possible future extensions, including automated garbage collection, object persistence, and concurrency. Other hypothetical future extensions that are described are dynamically linked libraries, rule-based programming, and extensible member functions. </p><CENTER><P><HR><A HREF="/publishers/que/series/professional/0789720221/index.htm"><img src="/publishers/que/series/professional/0789720221/button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A><BR><BR><BR><p></P><P>© <A HREF="/publishers/que/series/professional/0789720221/copy.htm">Copyright 1999</A>, Macmillan Computer Publishing. Allrights reserved.</p></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -