自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (6)
  • 收藏
  • 关注

空空如也

双向链表及其操作

算法:<br>typedef struct dnode {<br> elemtype data;<br> struct dnode *prior, *next;<br>} DNODE;<br><br><br>int link_ins(DNODE **head, int i, elemtype x)<br>{<br> int j = 1; /* 双向循环链表 */<br> DNODE *p, *q;<br> q = malloc( sizeof *p );<br> q->data = x;<br> if ( i == 0 ) {<br> q->prior = *head;<br> q->next = *head;<br> *head = q;<br> return 0;<br> }<br> p = *head;<br> j = 0;<br> while ( ++j < i && p != NULL )<br> p = p->next;<br> if ( i < 0 || j < i )<br> return 1;<br> else {<br> q->next = p->next;<br> p->next = q;<br> p->next->prior = q;<br> q->prior = p;<br> return 0;<br> }<br>}<br>分析:在上面的插入算法中,不需要移动别的元素,但必须<br>从头开始查找第i结点的地址,一旦找到插入位置,则插入结点<br>只需两条语句就可完成。该算法的时间复杂度为O(n)<br><br>

2007-09-18

顺序表及其操作

这个程序支持的操作如下:<br> 1. 创建顺序表<br> 2. 输入数据<br> 3. 插入数据<br> 4. 删除数据<br> 5. 求顺序表并集<br> 6. 删除重复元素<br> 7. 冒泡排序<br> 8. 比较顺序表大小<br> 9. 前N个元素和后M个元素互换<br> 10. 删除重复元素(2)<br> 0. 退出

2007-09-18

单链表及其操作

1、链接存储方法<br>  链接方式存储的线性表简称为链表(Linked List)。<br>  链表的具体存储表示为:<br>  ① 用一组任意的存储单元来存放线性表的结点(这组存储单元既可以是连续的,也可以是不连续的)<br>  ② 链表中结点的逻辑次序和物理次序不一定相同。为了能正确表示结点间的逻辑关系,在存储每个结点值的同时,还必须存储指示其后继结点的地址(或位置)信息(称为指针(pointer)或链(link))<br>注意:<br>  链式存储是最常用的存储方式之一,它不仅可用来表示线性表,而且可用来表示各种非线性的数据结构。<br><br>2、链表的结点结构<br> ┌──┬──┐<br> |data | next│<br> └──┴──┘ <br>  data域--存放结点值的数据域<br>  next域--存放结点的直接后继的地址(位置)的指针域(链域)<br>注意:<br>   ①链表通过每个结点的链域将线性表的n个结点按其逻辑顺序链接在一起的。<br>  ②每个结点只有一个链域的链表称为单链表(Single Linked List)。<br>3、头指针head和终端结点指针域的表示<br>  单链表中每个结点的存储地址是存放在其前趋结点next域中,而开始结点无前趋,故应设头指针head指向开始结点。<br>注意:<br>  链表由头指针唯一确定,单链表可以用头指针的名字来命名。<br>【例】头指针名是head的链表可称为表head。<br>  终端结点无后继,故终端结点的指针域为空,即NULL<br>4、单链表类型描述<br> typedef char DataType; /* 假设结点的数据域类型为字符 */<br> typedef struct node { /* 结点类型定义 */<br> DataType data; /* 结点的数据域 */<br> struct node *next; /* 结点的指针域 */<br> } ListNode;<br> typedef ListNode *LinkList;<br> ListNode *p;<br> LinkList head;<br> 注意:<br>  ①LinkList和ListNode *是不同名字的同一个指针类型(命名的不同是为了概念上更明确)<br>  ②LinkList类型的指针变量head表示它是单链表的头指针<br>  ③ListNode *类型的指针变量p表示它是指向某一结点的指针<br><br>6、指针变量和结点变量<br><br><br>┌────┬────────────┬─────────────┐ <br>│    │    指针变量    │     结点变量    │<br>├────┼────────────┼─────────────┤<br>│ 定义 │在变量说明部分显式定义 │在程序执行时,通过标准 │<br>│ │ │函数malloc生成 │<br>├────┼────────────┼─────────────┤<br>│ 取值 │ 非空时,存放某类型结点 │实际存放结点各域内容 │<br>│ │ 的地址 | │<br>├────┼────────────┼─────────────┤<br>│操作方式│ 通过指针变量名访问 │ 通过指针生成、访问和释放 │<br>└────┴────────────┴─────────────┘<br> <br>①生成结点变量的标准函数<br>  p = malloc( sizeof(ListNode) );<br> /* 函数malloc分配一个类型为ListNode的结点变量的空间,并将其首地址放入指针变量p中 */<br>②释放结点变量空间的标准函数 <br>  free(p); /* 释放p所指的结点变量空间 */<br>③结点分量的访问 <br>  利用结点变量的名字*p访问结点分量<br> 方法一:(*p).data和(*p).next<br> 方法二:p-﹥data和p-﹥next<br>④指针变量p和结点变量*p的关系 <br>  指针变量p的值——结点地址<br>  结点变量*p的值——结点内容<br>  (*p).data的值——p指针所指结点的data域的值<br>  (*p).next的值——*p后继结点的地址<br>  *((*p).next)——*p后继结点<br><br>注意:<br>   ① 若指针变量p的值为空(NULL),则它不指向任何结点。此时,若通过*p来访问结点就意味着访问一个不存在的变量,从而引起程序的错误。<br>   ② 有关指针类型的意义和说明方式的详细解释,【参考C语言的有关资料】。<br>

2007-09-18

C++ FAQs

C++ FAQs<br> Part I. Preliminaries <br> Chapter 1. Introduction <br> FAQ 1.01 What is the purpose of this chapter? <br> FAQ 1.02 What are C++ FAQs? <br> FAQ 1.03 Who is the target audience for this book? <br> FAQ 1.04 Is this a book about C++ per se? <br> FAQ 1.05 Why do developers need a guidebook for C++ and OO technology? <br> FAQ 1.06 What kind of guidance is given in the answers to these FAQs? <br> FAQ 1.07 What is the electronic FAQ and why buy this book when the electronic FAQ is free? <br> FAQ 1.08 Why should you buy this edition if you already have a copy of the first edition? <br> FAQ 1.09 What conventions are used in this book? <br> <br> Chapter 2. Basic C++ Syntax and Semantics <br> FAQ 2.01 What is the purpose of this chapter? <br> FAQ 2.02 What are the basics of main()? <br> FAQ 2.03 What are the basics of functions? <br> FAQ 2.04 What are the basics of default parameters? <br> FAQ 2.05 What are the basics of local (auto) objects? <br> FAQ 2.06 What are the basics of constructing objects using explicit parameters? <br> FAQ 2.07 What are the basics of dynamically allocated (new) objects? <br> FAQ 2.08 What are the basics of local objects within inner scopes? <br> FAQ 2.09 What are the basics of passing objects by reference? <br> FAQ 2.10 What are the basics of passing objects by value? <br> FAQ 2.11 What are the basics of passing objects by pointer? <br> FAQ 2.12 What are the basics of stream output? <br> FAQ 2.13 What are the basics of stream input? <br> FAQ 2.14 What are the basics of using classes that contain overloaded operators? <br> FAQ 2.15 What are the basics of using container classes? <br> FAQ 2.16 What are the basics of creating class header files? <br> FAQ 2.17 What are the basics of defining a class? <br> FAQ 2.18 What are the basics of defining member functions? <br> FAQ 2.19 What are the basics of adding a constructor to a class? <br> FAQ 2.20 What are the basics of adding a destructor to a class? <br> FAQ 2.21 What are the basics of defining a class that contains a pointer to an object allocated from the heap? <br> FAQ 2.22 What are the basics of global objects? <br> FAQ 2.23 What are the basics of throwing and catching exceptions? <br> FAQ 2.24 What are the basics of inheritance and dynamic binding? <br> <br> Chapter 3. Understanding the Management Perspective <br> FAQ 3.01 What is the purpose of this chapter? <br> FAQ 3.02 What is the core message of this chapter (and this book)? <br> FAQ 3.03 Why are the managers in charge rather than the developers who understand technology? <br> FAQ 3.04 How can someone manage something they don't understand? <br> FAQ 3.05 What is the most common mistake on C++ and OO projects? <br> FAQ 3.06 What's the "Software Peter Principle"? <br> FAQ 3.07 Should an organization use OO on all its projects? <br> FAQ 3.08 Can OO be ignored until it goes away? <br> FAQ 3.09 What OO language is best? <br> FAQ 3.10 What is the right approach to processes and tools? <br> FAQ 3.11 What is the right approach with off-the-shelf class libraries and frameworks? <br> <br> Chapter 4. The Architectural Perspective <br> FAQ 4.01 What is the purpose of this chapter? <br> FAQ 4.02 Why is software architecture important? <br> FAQ 4.03 What should the architecture be based on, the problem being solved or the problem domain? <br> FAQ 4.04 Should the software architecture be based on the policy of the problem? <br> FAQ 4.05 Do customers ever change their requirements? <br> FAQ 4.06 Are stable requirements desirable? <br> FAQ 4.07 What is the key to planning for change? <br> FAQ 4.08 What is a framework? <br> FAQ 4.09 What is the "inversion of control" exhibited by frameworks? <br> FAQ 4.10 What is an extensible, domain-specific framework? <br> FAQ 4.11 What characteristics make a framework extensible yet domain-specific? <br> FAQ 4.12 What happens if the domain analysis is incorrect? <br> FAQ 4.13 How much effort should be expended to support change梩hat is, how much is extensibility worth? <br> FAQ 4.14 How does an architect make the software architecture flexible? <br> FAQ 4.15 What is the secret to achieving reuse? <br> <br> <br> Part II. Object-Oriented Design <br> Chapter 5. Object-Oriented Fundamentals <br> FAQ 5.01 What is the purpose of this chapter? <br> FAQ 5.02 Why is the world adopting OO technology? <br> FAQ 5.03 What are some of the benefits of using C++ for OO programming? <br> FAQ 5.04 What are the fundamental concepts of object-oriented technology? <br> FAQ 5.05 Why are classes important? <br> FAQ 5.06 What is an object? <br> FAQ 5.07 What are the desirable qualities of an object? <br> FAQ 5.08 How are classes better than the three basic building blocks of procedural software? <br> FAQ 5.09 What is the purpose of composition? <br> FAQ 5.10 What is the purpose of inheritance? <br> FAQ 5.11 What are the advantages of polymorphism and dynamic binding? <br> FAQ 5.12 How does OO help produce flexible and extensible software? <br> FAQ 5.13 How can old code call new code? <br> FAQ 5.14 What is an abstraction and why is it important? <br> FAQ 5.15 Should abstractions be user-centric or developer-centric? <br> FAQ 5.16 What's the difference between encapsulation and abstraction? <br> FAQ 5.17 What are the consequences of encapsulating a bad abstraction? <br> FAQ 5.18 What's the value of separating interface from implementation? <br> FAQ 5.19 How can separating interface from implementation improve performance as well as flexibility? <br> FAQ 5.20 What is the best way to create a good interface to an abstraction? <br> FAQ 5.21 How are get/set member functions related to poorly designed interfaces? <br> FAQ 5.22 Should there be a get and a set member function for each member datum? <br> FAQ 5.23 Is the real purpose of a class to export data? <br> FAQ 5.24 Should OO be viewed as data-centric? <br> <br> Chapter 6. Specification of Observable Behavior <br> FAQ 6.01 What is the purpose of this chapter? <br> FAQ 6.02 Should users of a member function rely on what the code actually does or on the specification? <br> FAQ 6.03 What are the advantages of relying on the specification rather than the implementation? <br> FAQ 6.04 What are advertised requirements and advertised promises? <br> FAQ 6.05 How are the advertised requirements and advertised promises of the member functions specified? <br> FAQ 6.06 Why are changes feared in development organizations that don't use specification? <br> FAQ 6.07 How do developers determine if a proposed change will break existing code? <br> FAQ 6.08 What are the properties of a substitutable (backward compatible) change in a specification? <br> FAQ 6.09 How can it be shown that the implementation of a member function fulfills its specification? <br> FAQ 6.10 Is it possible to keep the specification synchronized with the code? <br> <br> Chapter 7. Proper Inheritance <br> FAQ 7.01 What is proper inheritance? <br> FAQ 7.02 What are the benefits of proper inheritance? <br> FAQ 7.03 What is improper inheritance? <br> FAQ 7.04 Isn't the difference between proper and improper inheritance obvious? <br> FAQ 7.05 Is substitutability based on what the code does or what the specification promises the code will do? <br> FAQ 7.06 Is it proper to revoke (hide) an inherited public: member function? <br> FAQ 7.07 What is specialization? <br> FAQ 7.08 What do subsets have to do with proper inheritance? <br> <br> Chapter 8. Detecting and Correcting Improper Inheritance <br> FAQ 8.01 Can improper inheritance wreck a project? <br> FAQ 8.02 What's the best way to learn how to avoid improper inheritance? <br> FAQ 8.03 Is intuition a reliable guide to understanding proper inheritance? <br> FAQ 8.04 Is an Ostrich a kind-of Bird? <br> FAQ 8.05 Should an overridden virtual function throw an exception? <br> FAQ 8.06 Can an overridden virtual function be a no-op? <br> FAQ 8.07 Why does C++ make it so hard to fix the Ostrich/Bird dilemma? <br> FAQ 8.08 Should Circle inherit from Ellipse? <br> FAQ 8.09 What can be done about the asymmetric-circle dilemma? <br> FAQ 8.10 What is the one issue in these FAQs that doesn't seem to die? <br> FAQ 8.11 Should Stack inherit from List? <br> FAQ 8.12 Is code reuse the main purpose of inheritance? <br> FAQ 8.13 Is container-of-thing a kind-of container-of-anything? <br> FAQ 8.14 Is bag-of-apple a kind-of bag-of-fruit, assuming bag-of-fruit allows the insertion of any kind-of fruit? <br> FAQ 8.15 Is parking-lot-for-cars a kind-of parking-lot-for-arbitrary-vehicles (assuming parking-lot-for-vehicles allows parking any kind-of vehicle)? <br> FAQ 8.16 Is array-of Derived a kind-of array-of Base? <br> FAQ 8.17 Does the fact that an array-of Derived can be passed as an array-of Base mean that arrays are bad? <br> <br> Chapter 9. Error Handling Strategies <br> FAQ 9.01 Is error handling a major source of fundamental mistakes? <br> FAQ 9.02 How should runtime errors be handled in C++? <br> FAQ 9.03 What happens to objects in stack frames that become unwound during the throw / catch process? <br> FAQ 9.04 What is an exception specification? <br> FAQ 9.05 What are the disadvantages of using return codes for error handling? <br> FAQ 9.06 What are the advantages of throw...catch? <br> FAQ 9.07 Why is it helpful to separate normal logic from exception handling logic? <br> FAQ 9.08 What is the hardest part of using exception handling? <br> FAQ 9.09 When should a function throw an exception? <br> FAQ 9.10 What is the best approach for the hierarchy of exception objects? <br> FAQ 9.11 How should exception classes be named? <br> FAQ 9.12 Where do setjmp and longjmp belong in C++? <br> <br> Chapter 10. Testing Strategies <br> FAQ 10.01 What is the purpose of this chapter? <br> FAQ 10.02 What are the advantages of self-testing objects? <br> FAQ 10.03 What are some common excuses people use for not building self-testing into their objects? <br> FAQ 10.04 What will happen if techniques like those presented here are not used? <br> FAQ 10.05 When is a class correct? <br> FAQ 10.06 What is behavioral self-testing? <br> FAQ 10.07 What is a class invariant? <br> FAQ 10.08 Why should the invariant be captured explicitly? <br> FAQ 10.09 When should the testInvariant() member function be called? <br> FAQ 10.10 What can be done to ensure that an object doesn't get blown away by a wild pointer? <br> <br> <br> Part III. Language Facilities <br> Chapter 11. References <br> FAQ 11.01 What is a reference? <br> FAQ 11.02 What does "referent" mean? <br> FAQ 11.03 When can a reference be attached to its referent? <br> FAQ 11.04 What happens when a value is assigned to a reference? <br> FAQ 11.05 What is a local reference? <br> FAQ 11.06 What does it mean to return a reference? <br> FAQ 11.07 What is the result of taking the address of a reference? <br> FAQ 11.08 Can a reference be made to refer to a different referent? <br> FAQ 11.09 Why use references when pointers can do everything references can do? <br> FAQ 11.10 Aren't references just pointers in disguise? <br> FAQ 11.11 When are pointers needed? <br> FAQ 11.12 Why do some people hate references? <br> FAQ 11.13 Does int& const x make sense? <br> <br> Chapter 12. New and Delete <br> FAQ 12.01 Does new do more than allocate memory? <br> FAQ 12.02 Why is new better than good old trustworthy malloc()? <br> FAQ 12.03 Does C++ have a counterpart to realloc() that goes along with new and delete? <br> FAQ 12.04 Can pointers returned from new be deallocated with free()? Can pointers returned from malloc() be deallocated with delete? <br> FAQ 12.05 Does delete p delete the pointer p or the referent *p? <br> FAQ 12.06 Should the pointer returned from new Fred() be checked to see if it is NULL? <br> FAQ 12.07 How can new be convinced to return NULL rather than throw an exception? <br> FAQ 12.08 How can new be set up to automatically flush pools of recycled objects whenever memory runs low? <br> FAQ 12.09 What happens if delete p is called when p is NULL? <br> FAQ 12.10 What happens when a pointer is deleted twice? <br> FAQ 12.11 How can an array of things be allocated and deallocated? <br> FAQ 12.12 What if delete p (not delete[] p) is used to delete an array allocated via new Fred[n]? <br> FAQ 12.13 Can the [] of delete[] p be dropped when p points to an array of some built-in type such as char? <br> FAQ 12.14 How is an object constructed at a predetermined position in memory? <br> FAQ 12.15 How can class Fred guarantee that Fred objects are created only with new and not on the stack? <br> FAQ 12.16 How are objects created by placement new destroyed? <br> FAQ 12.17 In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception? <br> FAQ 12.18 Is it legal (and moral) for a member function to say delete this? <br> FAQ 12.19 After p = new Fred[n], how does the compiler know that there are n objects to be destructed during delete[] p? <br> <br> Chapter 13. Inline Functions <br> FAQ 13.01 What is the purpose of inline functions? <br> FAQ 13.02 What is the connection between the keyword "inline" and "inlined" functions? <br> FAQ 13.03 Are there any special rules about inlining? <br> FAQ 13.04 What is the one-definition rule (ODR)? <br> FAQ 13.05 What are some performance considerations with inline functions? <br> FAQ 13.06 Do inlined functions improve performance? <br> FAQ 13.07 Do inlined functions increase the size of the executable code? <br> FAQ 13.08 Why shouldn't the inlining decision be made when the code is first written? <br> FAQ 13.09 What happens when a programmer uses an inlined function obtained from a third party? <br> FAQ 13.10 Is there an easy way to swap between inline and non-inline code? <br> <br> Chapter 14. Const Correctness <br> FAQ 14.01 How should pointer declarations be read? <br> FAQ 14.02 How can C++ programmers avoid making unexpected changes to objects? <br> FAQ 14.03 Does const imply runtime overhead? <br> FAQ 14.04 Does const allow the compiler to generate more efficient code? <br> FAQ 14.05 Is const correctness tedious? <br> FAQ 14.06 Why should const correctness be done sooner rather than later? <br> FAQ 14.07 What's the difference between an inspector and a mutator? <br> FAQ 14.08 When should a member function be declared as const? <br> FAQ 14.09 Does const apply to the object's bitwise state or its abstract state? <br> FAQ 14.10 When should const not be used in declaring formal parameters? <br> FAQ 14.11 When should const not be used in declaring a function return type? <br> FAQ 14.12 How can a "nonobservable" data member be updated within a const member function? <br> FAQ 14.13 Can an object legally be changed even though there is a const reference (pointer) to it? <br> FAQ 14.14 Does const_cast mean lost optimization opportunities? <br> <br> Chapter 15. Namespaces <br> FAQ 15.01 What is the purpose of this chapter? <br> FAQ 15.02 What is a namespace? <br> FAQ 15.03 How can code outside a namespace use names declared within that namespace? <br> FAQ 15.04 What happens if two namespaces contain the same name? <br> FAQ 15.05 What are some of the rules for using namespaces? <br> FAQ 15.06 What is name lookup? <br> FAQ 15.07 What are the tradeoffs between the various techniques for using names from a namespace, particularly the standard namespace? <br> FAQ 15.08 Can namespaces break code? <br> FAQ 15.09 Do namespaces have any other applications? <br> FAQ 15.10 How do namespaces solve the problem of long identifiers? <br> <br> Chapter 16. Using Static <br> FAQ 16.01 What is the purpose of this chapter? <br> FAQ 16.02 What are static class members? <br> FAQ 16.03 What is an analogy for static data members? <br> FAQ 16.04 Can inline functions safely access static data members? <br> FAQ 16.05 What is an analogy for static member functions? <br> FAQ 16.06 How is a static data member similar to a global variable? <br> FAQ 16.07 How is a static member function similar to a friend function? <br> FAQ 16.08 What is the named constructor idiom? <br> FAQ 16.09 How should static member functions be called? <br> FAQ 16.10 Why might a class with static data members get linker errors? <br> FAQ 16.11 How is a const static data member initialized? <br> FAQ 16.12 What is the right strategy for implementing a function that needs to maintain state between calls? <br> FAQ 16.13 How can the function call operator help with functionoids? <br> FAQ 16.14 Is it safe to be ignorant of the static initialization order problem? <br> FAQ 16.15 What is a simple and robust solution to the static initialization order problem? <br> FAQ 16.16 What if the static object's destructor has important side effects that must eventually occur? <br> FAQ 16.17 What if the static object's destructor has important side effects that must eventually occur and the static object must be accessed by another static object's destructor? <br> FAQ 16.18 What are some criteria for choosing between all these various techniques? <br> <br> Chapter 17. Derived Classes <br> FAQ 17.01 What is the purpose of this chapter? <br> FAQ 17.02 How does C++ express inheritance? <br> FAQ 17.03 What is a concrete derived class? <br> FAQ 17.04 Why can't a derived class access the private: members of its base class? <br> FAQ 17.05 How can a base class protect derived classes so that changes to the base class will not affect them? <br> FAQ 17.06 Can a derived class pointer be converted into a pointer to its public base class? <br> FAQ 17.07 How can a class Y be a kind-of another class X as well as getting the bits of X? <br> FAQ 17.08 How can a class Y get the bits of an existing class X without making Y a kind-of X? <br> FAQ 17.09 How can a class Y be a kind-of another class X without inheriting the bits of X? <br> <br> Chapter 18. Access Control <br> FAQ 18.01 What is the purpose of this chapter? <br> FAQ 18.02 How are private:, protected:, and public: different? <br> FAQ 18.03 Why can't subclasses access the private: parts of their base class? <br> FAQ 18.04 What's the difference between the keywords struct and class? <br> FAQ 18.05 When should a data member be protected: rather than private:? <br> FAQ 18.06 Why is private: the default access level for a class? <br> <br> Chapter 19. Friend Classes and Friend Functions <br> FAQ 19.01 What is a friend? <br> FAQ 19.02 What's a good mental model for friend classes? <br> FAQ 19.03 What are some advantages of using friend classes? <br> FAQ 19.04 Do friends violate the encapsulation barrier? <br> FAQ 19.05 What is a friend function? <br> FAQ 19.06 When should a function be implemented as a friend function rather than a member function? <br> FAQ 19.07 What are some guidelines to make sure friend functions are used properly? <br> FAQ 19.08 What does it mean that friendship isn't transitive? <br> FAQ 19.09 What does it mean that friendship isn't inherited? <br> FAQ 19.10 What does it mean that friends aren't virtual? <br> FAQ 19.11 What qualities suggest a friend function rather than a member function? <br> FAQ 19.12 Should friend functions be declared in the private:, protected:, or public: section of a class? <br> FAQ 19.13 What is a private class? <br> FAQ 19.14 How are objects of a class printed? <br> FAQ 19.15 How do objects of a class receive stream input? <br> <br> Chapter 20. Constructors and Destructors <br> FAQ 20.01 What is the purpose of a constructor? <br> FAQ 20.02 What is C++'s constructor discipline? <br> FAQ 20.03 What is the purpose of a destructor? <br> FAQ 20.04 What is C++'s destructor discipline? <br> FAQ 20.05 What happens when a destructor is executed? <br> FAQ 20.06 What is the purpose of a copy constructor? <br> FAQ 20.07 When is a copy constructor invoked? <br> FAQ 20.08 What is the "default constructor"? <br> FAQ 20.09 Should one constructor call another constructor as a primitive? <br> FAQ 20.10 Does the destructor for a derived class need to explicitly call the destructor of its base class? <br> FAQ 20.11 How can a local object be destructed before the end of its function? <br> FAQ 20.12 What is a good way to provide intuitive, multiple constructors for a class? <br> FAQ 20.13 When the constructor of a base class calls a virtual function, why isn't the override called? <br> FAQ 20.14 When a base class destructor calls a virtual function, why isn't the override called? <br> FAQ 20.15 What is the purpose of placement new? <br> <br> Chapter 21. Virtual Functions <br> FAQ 21.01 What is the purpose of this chapter? <br> FAQ 21.02 What is a virtual member function? <br> FAQ 21.03 How much does it cost to call a virtual function compared to calling a normal function? <br> FAQ 21.04 How does C++ perform static typing while supporting dynamic binding? <br> FAQ 21.05 Can destructors be virtual? <br> FAQ 21.06 What is the purpose of a virtual destructor? <br> FAQ 21.07 What is a virtual constructor? <br> FAQ 21.08 What syntax should be used when a constructor or destructor calls a virtual function in its object? <br> FAQ 21.09 Should the scope operator :: be used when invoking virtual member functions? <br> FAQ 21.10 What is a pure virtual member function? <br> FAQ 21.11 Can a pure virtual function be defined in the same class that declares it? <br> FAQ 21.12 How should a virtual destructor be defined when it has no code? <br> FAQ 21.13 Can an ABC have a pure virtual destructor? <br> FAQ 21.14 How can the compiler be kept from generating duplicate outlined copies of inline virtual functions? <br> FAQ 21.15 Should a class with virtual functions have at least one non-inline virtual function? <br> <br> Chapter 22. Initialization Lists <br> FAQ 22.01 What are constructor initialization lists? <br> FAQ 22.02 What will happen if constructor initialization lists are not used? <br> FAQ 22.03 What's the guideline for using initialization lists in constructor definitions? <br> FAQ 22.04 Is it normal for constructors to have nothing inside their body? <br> FAQ 22.05 How is a const data member initialized? <br> FAQ 22.06 How is a reference data member initialized? <br> FAQ 22.07 Are initializers executed in the same order in which they appear in the initialization list? <br> FAQ 22.08 How should initializers be ordered in a constructor's initialization list? <br> FAQ 22.09 Is it moral for one member object to be initialized using another member object in the constructor's initialization list? <br> FAQ 22.10 What if one member object has to be initialized using another member object? <br> FAQ 22.11 Are there exceptions to the rule "Initialize all member objects in an initialization list"? <br> FAQ 22.12 How can an array of objects be initialized with specific initializers? <br> <br> Chapter 23. Operator Overloading <br> FAQ 23.01 Are overloaded operators like normal functions? <br> FAQ 23.02 When should operator overloading be used? <br> FAQ 23.03 What operators can't be overloaded? <br> FAQ 23.04 Is the goal of operator overloading to make the class easier to understand? <br> FAQ 23.05 Why do subscript operators usually come in pairs? <br> FAQ 23.06 What is the most important consideration for operators such as +=, +, and =? <br> FAQ 23.07 How are the prefix and postfix versions of operator++ distinguished? <br> FAQ 23.08 What should the prefix and postfix versions of operator++ return? <br> FAQ 23.09 How can a Matrix-like class have a subscript operator that takes more than one subscript? <br> FAQ 23.10 Can a ** operator serve as an exponentiation operator? <br> <br> Chapter 24. Assignment Operators <br> FAQ 24.01 What should assignment operators return? <br> FAQ 24.02 What is wrong with an object being assigned to itself? <br> FAQ 24.03 What should be done about self-assignment? <br> FAQ 24.04 Should an assignment operator throw an exception after partially assigning an object? <br> FAQ 24.05 How should the assignment operator be declared in an ABC? <br> FAQ 24.06 When should a user-defined assignment operator mimic the assignment operator that the compiler would generate automatically? <br> FAQ 24.07 What should be returned by private: and protected: assignment operators? <br> FAQ 24.08 Are there techniques that increase the likelihood that the compiler-synthesized assignment operator will be right? <br> FAQ 24.09 How should the assignment operator in a derived class behave? <br> FAQ 24.10 Can an ABC's assignment operator be virtual? <br> FAQ 24.11 What should a derived class do if a base class's assignment operator is virtual? <br> FAQ 24.12 Should the assignment operator be implemented by using placement new and the copy constructor? <br> <br> Chapter 25. Templates <br> FAQ 25.01 What is the purpose of templates? <br> FAQ 25.02 What are the syntax and semantics for a class template? <br> FAQ 25.03 How can a template class be specialized to handle special cases? <br> FAQ 25.04 What are the syntax and semantics for a function template? <br> FAQ 25.05 Should a template use memcpy() to copy objects of its template argument? <br> FAQ 25.06 Why does the compiler complain about >> when one template is used inside another? <br> <br> Chapter 26. Exception Tactics <br> FAQ 26.01 What belongs in a try block? <br> FAQ 26.02 When should a function catch an exception? <br> FAQ 26.03 Should a catch block fully recover from an error? <br> FAQ 26.04 How should a constructor handle a failure? <br> FAQ 26.05 What are zombie objects (and why should they be avoided)? <br> FAQ 26.06 What should an object do if one of its member objects could throw an exception during its constructor? <br> FAQ 26.07 Should destructors throw exceptions when they fail? <br> FAQ 26.08 Should destructors call routines that may throw exceptions? <br> FAQ 26.09 Should resource deallocation primitives signal failure by throwing an exception? <br> FAQ 26.10 What should the terminate() function do? <br> FAQ 26.11 What should the unexpected() function do? <br> FAQ 26.12 Under what circumstances can an overridden virtual member function throw exceptions other than those listed by the specification of the member function in the base class? <br> FAQ 26.13 How might the exception-handling mechanism cause a program to silently crash? <br> <br> Chapter 27. Types and RTTI <br> FAQ 27.01 What is the purpose of this chapter? <br> FAQ 27.02 What is static type checking? <br> FAQ 27.03 What is dynamic type checking? <br> FAQ 27.04 What is the basic problem with dynamic type checking? <br> FAQ 27.05 How can dynamic type checking be avoided? <br> FAQ 27.06 Are there better alternatives to dynamic type checking? <br> FAQ 27.07 What is a capability query? <br> FAQ 27.08 What is an alternative to dynamic type checking with containers? <br> FAQ 27.09 Are there cases where dynamic type checking is necessary? <br> FAQ 27.10 Given a pointer to an ABC, how can the class of the referent be found? <br> FAQ 27.11 What is a downcast? <br> FAQ 27.12 What is an alternative to using downcasts? <br> FAQ 27.13 Why are downcasts dangerous? <br> FAQ 27.14 Should the inheritance graph of C++ hierarchies be tall or short? <br> FAQ 27.15 Should the inheritance graph of C++ hierarchies be monolithic or a forest? <br> FAQ 27.16 What is Runtime Type Identification (RTTI)? <br> FAQ 27.17 What is the purpose of dynamic_cast<T>()? <br> FAQ 27.18 Is dynamic_cast<T>() a panacea? <br> FAQ 27.19 What does static_cast<T>() do? <br> FAQ 27.20 What does typeid() do? <br> FAQ 27.21 Are there any hidden costs for type-safe downcasts? <br> <br> Chapter 28. Containers <br> FAQ 28.01 What are container classes and what are the most common mistakes made with container classes? <br> FAQ 28.02 Are arrays good or evil? <br> FAQ 28.03 Should application development organizations create their own container classes? <br> FAQ 28.04 What are some common mistakes with containers of pointers? <br> FAQ 28.05 Does this mean that containers of pointers should be avoided? <br> FAQ 28.06 Surely good old-fashioned char* is an exception, right? <br> FAQ 28.07 Can auto_ptr<T> simplify ownership problems with containers of pointers? <br> FAQ 28.08 Can a Java-like Object class simplify containers in C++? <br> FAQ 28.09 What's the difference between a homogeneous and a heterogeneous container? <br> FAQ 28.10 Is it a good idea to use a "best of breed" approach when selecting container classes? <br> FAQ 28.11 Should all projects use C++'s standardized containers? <br> FAQ 28.12 What are the C++ standardized container classes? <br> FAQ 28.13 What are the best applications for the standardized C++ sequence container classes? <br> FAQ 28.14 What are the best situations for the standardized C++ associative container classes? <br> <br> <br> Part IV. Topics <br> Chapter 29. Mixing Overloading with Inheritance <br> FAQ 29.01 What is the difference between overloaded functions and overridden functions? <br> FAQ 29.02 What is the hiding rule? <br> FAQ 29.03 How should the hiding rule be handled? <br> FAQ 29.04 What should a derived class do when it redefines some but not all of a set of overloaded member functions inherited from the base class? <br> FAQ 29.05 Can virtual functions be overloaded? <br> <br> Chapter 30. The Big Three <br> FAQ 30.01 What is the purpose of this chapter? <br> FAQ 30.02 What are the Big Three? <br> FAQ 30.03 What happens when an object is destroyed that doesn't have an explicit destructor? <br> FAQ 30.04 What happens if an object is copied but doesn't have an explicit copy constructor? <br> FAQ 30.05 What happens when an object that doesn't have an explicit assignment operator is assigned? <br> FAQ 30.06 What is the Law of the Big Three? <br> FAQ 30.07 Which of the Big Three usually shows up first? <br> FAQ 30.08 What is remote ownership? <br> FAQ 30.09 How is remote ownership special? <br> FAQ 30.10 What if a class owns a referent and doesn't have all of the Big Three? <br> FAQ 30.11 Are there any C++ classes that help manage remote ownership? <br> FAQ 30.12 Does auto_ptr enforce the Law of the Big Three and solve the problems associated with remote ownership? <br> FAQ 30.13 Are there cases where one or two of the Big Three may be needed but not all three? <br> FAQ 30.14 Are there any other circumstances that might explicitly warrant the Big Three? <br> FAQ 30.15 Why does copying an object using memcpy() cause a program crash? <br> FAQ 30.16 Why do programs with variable-length argument lists crash? <br> FAQ 30.17 Why do programs that use realloc() to reallocate an array of objects crash? <br> <br> Chapter 31. Using Objects to Prevent Memory Leaks <br> FAQ 31.01 When are memory leaks important? <br> FAQ 31.02 What is the easiest way to avoid memory leaks? <br> FAQ 31.03 What are the most important principles for resource management? <br> FAQ 31.04 Should the object that manages a resource also perform operations that may throw exceptions? <br> FAQ 31.05 Should an object manage two or more resources? <br> FAQ 31.06 What if an object has a pointer to an allocation and one of the object's member functions deletes the allocation? <br> FAQ 31.07 How should a pointer variable be handled after being passed to delete? <br> FAQ 31.08 What should be done with a pointer to an object that is allocated and deallocated in the same scope? <br> FAQ 31.09 How easy is it to implement reference counting with pointer semantics? <br> FAQ 31.10 Is reference counting with copy-on-write semantics hard to implement? <br> FAQ 31.11 How can reference counting be implemented with copy-on-write semantics for a hierarchy of classes? <br> <br> Chapter 32. Wild Pointers and Other Devilish Errors <br> FAQ 32.01 What is a wild pointer? <br> FAQ 32.02 What happens to a program that has even one wild pointer? <br> FAQ 32.03 What does the compiler mean by the warning "Returning a reference to a local object"? <br> FAQ 32.04 How should pointers across block boundaries be controlled? <br> FAQ 32.05 Is the reference-versus-pointer issue influenced by whether or not the object is allocated from the heap? <br> FAQ 32.06 When should C-style pointer casts be used? <br> FAQ 32.07 Is it safe to bind a reference variable to a temporary object? <br> FAQ 32.08 Should a parameter passed by const reference be returned by const reference? <br> FAQ 32.09 Should template functions for things like min(x,y) or abs(x) return a const reference? <br> FAQ 32.10 When is zero not necessarily zero? <br> <br> Chapter 33. High-Performance Software <br> FAQ 33.01 Is bad performance a result of bad design or bad coding? <br> FAQ 33.02 What are some techniques for improving performance? <br> FAQ 33.03 What is an advantage of using pointers and references? <br> FAQ 33.04 What is a disadvantage of lots of references and pointers? <br> FAQ 33.05 How else can member objects improve performance over pointers? <br> FAQ 33.06 Which is better, ++i or i++? <br> FAQ 33.07 What is the performance difference between Fred x(5); and Fred y = 5; and Fred z = Fred(5);? <br> FAQ 33.08 What kinds of applications should consider using final classes and final member functions? <br> FAQ 33.09 What is a final class? <br> FAQ 33.10 What is a final member function? <br> FAQ 33.11 How can final classes and final member functions improve performance? <br> FAQ 33.12 When should a nonfinal virtual function be invoked with a fully qualified name? <br> FAQ 33.13 Should full qualification be used when calling another member function of the same class? <br> FAQ 33.14 Do final classes and final member functions cause a lot of code duplication? <br> FAQ 33.15 Why do some developers dislike final member functions and final classes? <br> FAQ 33.16 Can a programming language梤ather than just the compiler梐ffect the performance of software? <br> <br> Chapter 34. COM and ActiveX <br> FAQ 34.01 Who should read this chapter? <br> FAQ 34.02 What is the Component Object Model? <br> FAQ 34.03 What are ActiveX and OLE? <br> FAQ 34.04 What does the name Component Object Model mean? <br> FAQ 34.05 What is a "binary object model"? <br> FAQ 34.06 What are the key features of COM? <br> FAQ 34.07 What are GUIDs? <br> FAQ 34.08 Why does COM need GUIDs (and CLSIDs and IIDs)? <br> FAQ 34.09 What is an interface? <br> FAQ 34.10 What is the IUnknown interface? <br> FAQ 34.11 How many ways are there to specify COM interfaces? <br> FAQ 34.12 What are COM classes and COM objects? <br> FAQ 34.13 How hard is it for callers to create and use a COM object? <br> FAQ 34.14 How does COM provide language transparency? <br> FAQ 34.15 How does COM provide location transparency? <br> FAQ 34.16 What types of errors occur due to reference counting? <br> FAQ 34.17 What mechanism does COM define for error handling? <br> FAQ 34.18 How are interfaces versioned? <br> FAQ 34.19 Is COM object oriented? <br> FAQ 34.20 What is the biggest problem with COM? <br> FAQ 34.21 What are the major differences between COM and C++? <br> FAQ 34.22 When should a class be defined as a COM class? <br> FAQ 34.23 What is Automation? <br> FAQ 34.24 What are dispatch interfaces? <br> FAQ 34.25 When should a class expose a Dispatch interface? <br> FAQ 34.26 How does Automation work? <br> FAQ 34.27 How does Invoke accomplish all of this? <br> FAQ 34.28 What is a type library? <br> FAQ 34.29 What are the benefits of using type libraries? <br> FAQ 34.30 How do type libraries improve performance? <br> FAQ 34.31 What are dual interfaces? <br> FAQ 34.32 What limitations are there on dual interfaces? <br> FAQ 34.33 What are OLE custom controls and ActiveX controls? <br> FAQ 34.34 Why do ActiveX controls differ from OLE custom controls? <br> FAQ 34.35 What is a control container? <br> FAQ 34.36 What are component categories? <br> FAQ 34.37 What are events? <br> FAQ 34.38 What is DCOM? <br> FAQ 34.39 How stable is DCOM's infrastructure? <br> FAQ 34.40 What is COM+? <br> <br> Chapter 35. Transitioning to CORBA <br> FAQ 35.01 What is CORBA? <br> FAQ 35.02 What is an ORB? <br> FAQ 35.03 What is IDL? <br> FAQ 35.04 What is COS? <br> FAQ 35.05 What is OMA? <br> FAQ 35.06 What is OMG? <br> FAQ 35.07 What is the purpose of this chapter? <br> FAQ 35.08 What is the most important message of this chapter? <br> FAQ 35.09 What are the important concepts behind CORBA? <br> FAQ 35.10 Isn't OMG IDL pretty much the same as C++? <br> FAQ 35.11 Is the lifecycle of a CORBA object the same as the life cycle of a C++ object? <br> FAQ 35.12 Is the C++ code that interacts with the CORBA implementation portable to a different CORBA vendor? <br> FAQ 35.13 How do CORBA exceptions compare to C++ exceptions? <br> FAQ 35.14 Which CORBA implementation is best? Is CORBA better than COM? <br> <br> Chapter 36. C Language Considerations <br> FAQ 36.01 What are the main issues when mixing C and C++ code in the same application? <br> FAQ 36.02 How can C++ code call C code? <br> FAQ 36.03 How can C code call C++ code? <br> FAQ 36.04 Why is the linker giving errors for C functions called from C++ functions and vice versa? <br> FAQ 36.05 How can an object of a C++ class be passed to or from a C function? <br> FAQ 36.06 Can a C function directly access data in an object of a C++ class? <br> FAQ 36.07 Can C++ I/O (<iostream>) be mixed with C I/O (<stdio.h>)? <br> FAQ 36.08 Which is safer: <iostream> or <stdio.h>? <br> FAQ 36.09 Which is more extensible: <iostream> or <stdio.h>? <br> FAQ 36.10 Which is more flexible: <iostream> or <stdio.h>? <br> FAQ 36.11 Why does it seem that C++ programming feels farther away from the machine than C? <br> FAQ 36.12 Why does C++ do more things behind your back than C does? <br> <br> Chapter 37. Private and Protected Inheritance <br> FAQ 37.01 What are private inheritance and protected inheritance? <br> FAQ 37.02 What is the difference between private inheritance and protected inheritance? <br> FAQ 37.03 What is the syntax and semantics for private and protected inheritance? <br> FAQ 37.04 When should normal has-a be used, rather than private or protected inheritance? <br> FAQ 37.05 What are the access rules for public, protected, and private inheritance? <br> FAQ 37.06 In a private or protected derived class, how can a member function that was public in the base class be made public in the derived class? <br> FAQ 37.07 Should a pointer be cast from a private or protected derived class to its base class? <br> <br> Chapter 38. Pointers to Member Functions <br> FAQ 38.01 What is the type of a pointer to a nonstatic member function? <br> FAQ 38.02 Can pointers to nonstatic member functions be passed to signal handlers, X event call-back handlers, and so on, that expect C-like function pointers? <br> FAQ 38.03 What is one of the most common errors when using pointers to member functions? <br> FAQ 38.04 How is an array of pointers to nonstatic member functions declared? <br> <br> Chapter 39. The Transition to OO and C++ <br> FAQ 39.01 Who should read this chapter? <br> FAQ 39.02 What are the key messages of this chapter? <br> FAQ 39.03 How many stages of technical expertise are there in the transition? <br> FAQ 39.04 Why bother defining levels of expertise? <br> FAQ 39.05 Can OO/C++ be learned from a book? <br> FAQ 39.06 Can OO/C++ be learned from a course? <br> FAQ 39.07 What is the key to learning OO/C++? <br> FAQ 39.08 Are small projects a good way to get your feet wet? <br> FAQ 39.09 Does being a good C programmer help when learning OO/C++? <br> FAQ 39.10 What skills help when learning OO/C++? <br>

2007-09-15

微软C编程精粹

微软C编程精粹<br>序 4<br>命名约定 6<br>某些背景 7<br>引言 8<br>第1章 假想的编译程序 12<br>第2章 自己设计并使用断言 20<br>第3章 为子系统设防 45<br>第4章 对程序进行逐条跟踪 68<br>第5章 糖果机界面 76<br>第6章 风险事业 92<br>第7章 编码中的假象 116<br>第8章 剩下来的就是态度问题 134<br>附录A 编码检查表 149<br>附录B 内存登录例程 152<br>附录C 练习答案 160<br>后记 走向何方 183<br><br>

2007-09-15

堆和栈的区别

堆和栈的区别 一、预备知识—程序的内存分配 二、堆和栈的理论知识 三、windows进程中的内存结构

2007-09-15

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除