• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我輩豈是蓬蒿人!

            C++ && keyWordSpotting

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              11 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(9)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 7245
            • 排名 - 1369

            最新評論

            閱讀排行榜

            評論排行榜

            Shifting from C to C++

            1. To C++ programmer, for example, a pointer to a pointer looks a little funny. Why, we wonder, wasn’t a reference to a pointer used ?instead?

            ?????? const char chr[] = "chenzhenshi&guohonghua";

            ?????? const char*? pchr = chr;

            ?????? const char** ppchr = &pchr;

            ?????? const char*&? rpchr? = pchr; // a reference to a pointer

            ?????? std::cout << pchr << ' ' << *ppchr << ' ' << rpchr << std::endl;

            ?

            2. C is a fairly simple language. All it really offers is macros, pointers, structs, arrays, and functions. No matter what the problem is, the solution will always boil down to macros, pointers, structs, arrays, and functions. Not so in C++. The macros, pointers, structs, arrays and functions are still there, of course, but so are private and protected members, function overloading, default parameters, constructors and destructors, user-defined operators, inline functions, references, friends, templates, exceptions, namespaces, and more. The design space is much richer in C++ than it is in C: there are just a lot more options to consider.

            Item 1: Prefer const and inline to #define

            3. The Item might better be called “prefer the compiler to the preprocessor”.

            4. ?? const char* pc;

            ?????? pc = a1;

            ?????? std::cout << pc << std::endl;

            ?????? pc = a2;

            ?????? std::cout << pc << std::endl;

            ?

            ?????? const char* const pcc = "a const pointer to a const char array";

            ?????? std::cout << pcc << std::endl;

            ?????? // error C2166: l-value specifies const object

            ?????? // pcc = a1;? // error!

            ?????? std::cout << pcc << std::endl;

            5. You can define a const variable in a class, but it must be static const, and have a definition in an implementation file.

            // .h file

            class try_const

            {

            public:

            ?????? static const int num;

            };

            // .cxx file

            const int try_const::num = 250;

            6. You can get all the efficiency of a macro plus all the predictable behavior and type safety of a regular function by using an inline function.

            Template <class type>

            Inline const type& max (const type& a, const type& b)

            {

            Return a > b ? a : b ;

            }

            7. Given the availability of consts and inlines, your need for the preprocessor is reduced, but it's not completely eliminated. The day is far from near when you can abandon #include, and #ifdef/#ifndef continue to play important roles in controlling compilation. It's not yet time to retire the preprocessor, but you should definitely plan to start giving it longer and more frequent vacations.

            Item 2: Prefer <iostream> to <stdio.h>

            8. ?scanf and printf are not type-safe and extensible.

            9.? In particular, if you #include <iostream>, you get the elements of the iostream library ensconced within the namespace std (see Item 28), but if you #include <iostream.h>, you get those same elements at global scope. Getting them at global scope can lead to name conflicts, precisely the kinds of name conflicts the use of namespaces is designed to prevent.

            Item 3: Prefer new and delete to malloc and free

            10. The problem with malloc and free(and their variants) is simple : they don’t know about constructors and destructors.

            11. free 操作不會調(diào)用析構(gòu)函數(shù),如果指針?biāo)笇ο蟊旧碛址峙淞藘?nèi)存,則會造成內(nèi)存丟失。

            Item 4: Prefer C++ style comments

            Memory Management

            12. Memory management concerns in C++ fall into two general camps: getting it right and making it perform efficiently.

            Item 5: Use the same form in corresponding uses of new and delete

            13. When you use new, two things happen. First, memory is allocated. Second, one or more constructors are called for that memory. When you use delete, two other things happen: one or more destructors are called for the memory, then the memory is deallocated.

            14. The standard C++ library includes string and vector templates that reduce the need for built-in arrays to nearly zero.

            Item 6: Use delete on pointer members in destructors

            15. Speaking of smart pointers, one way to avoid the need to delete pointer members is to replace those members with smart pointer objects like the standard C++ Library’s auto_ptr.

            Item 7: Be prepared for out-of-memory conditions

            Item 8: Adhere to convention when writing operator new and operator delete

            Item 9: Avoid hiding the “normal” form of new

            Item 10: Write operator delete if you write operator new

            讓我們回過頭去看看這樣一個基本問題:為什么有必要寫自己的 operator new operator delete ?答案通常是:為了效率。缺省的 operator new operator delete 具有非常好的通用性,它的這種靈活性也使得在某些特定的場合下,可以進一步改善它的性能。尤其在那些需要動態(tài)分配大量的但很小的對象的應(yīng)用程序里,情況更是如此。

            ?

            posted on 2006-08-22 17:24 keyws 閱讀(523) 評論(0)  編輯 收藏 引用 所屬分類: 讀書筆記
            久久精品国产精品国产精品污| 国产AV影片久久久久久 | 亚洲第一极品精品无码久久 | 国产成人久久精品一区二区三区| 久久精品日日躁夜夜躁欧美| 国产精品久久久久影视不卡| 久久婷婷五月综合成人D啪| 亚洲国产精品无码成人片久久| 91麻精品国产91久久久久| 一本一道久久a久久精品综合| 国产精品美女久久久| 国产精品亚洲综合久久| 久久香蕉综合色一综合色88| 精品国产99久久久久久麻豆| 精品无码久久久久久久久久| 久久精品国产亚洲av日韩| 无夜精品久久久久久| 国内精品欧美久久精品| 国产亚洲精久久久久久无码| 久久久无码精品亚洲日韩京东传媒 | 国产精品成人精品久久久| 蜜臀av性久久久久蜜臀aⅴ| 久久综合鬼色88久久精品综合自在自线噜噜 | 日韩欧美亚洲综合久久影院d3| 久久婷婷午色综合夜啪| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 亚洲精品无码久久久| 精品久久久久久99人妻| 日本免费久久久久久久网站| 99国产欧美精品久久久蜜芽| 欧美午夜精品久久久久免费视| 久久婷婷国产剧情内射白浆| 欧美国产成人久久精品| 久久伊人精品一区二区三区| 亚洲人AV永久一区二区三区久久| 久久亚洲精品无码播放| 久久九九久精品国产| 久久丝袜精品中文字幕| 午夜肉伦伦影院久久精品免费看国产一区二区三区| 久久综合九色综合精品| 久久93精品国产91久久综合|