• <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>

            給學(xué)習(xí)c++的新手,這些書(shū)籍都是很經(jīng)典的。經(jīng)典中的經(jīng)典
            深度探索C++對(duì)象模型
            英文版:http://www.nengxia.com/soft.asp?id=5
            中文版:http://www.nengxia.com/soft.asp?id=19

            Modern C++ Design
            http://www.nengxia.com/soft.asp?id=7

            c++編程思想
            第一卷:
            中文版:http://www.nengxia.com/soft.asp?id=1039
            英文版: Prentice Hall Bruce Eckel Thinking In C++, Second EditionVolume.1
            第二卷:
            中文版:http://www.nengxia.com/soft.asp?id=1040
            英文版:http://www.nengxia.com/soft.asp?id=1041


            c++ Programming language
            中文版:http://www.nengxia.com/soft.asp?id=1038
            英文版:http://www.nengxia.com/soft.asp?id=368

            C++ Primer
            第三版中文版:http://www.nengxia.com/soft.asp?id=6
            第四版
            英文版:http://www.nengxia.com/soft.asp?id=117
            中文版:http://www.nengxia.com/soft.asp?id=635
            c++ primer 題解
            http://www.nengxia.com/soft.asp?id=17


            C++ Primer plus 第4版中文:
            中文版:http://www.nengxia.com/soft.asp?id=987
            英文版:
            Third.Editionhttp://www.nengxia.com/soft.asp?id=1037
            Special.Edition:http://www.nengxia.com/soft.asp?id=369


            Effective C++
            中文版:http://www.nengxia.com/soft.asp?id=9
            英文版:http://www.nengxia.com/soft.asp?id=1033

            More Effective C++
            中文版:http://www.nengxia.com/soft.asp?id=8

            STL源碼剖析
            http://www.nengxia.com/soft.asp?id=11


            c++ template
            英文版:
            http://www.nengxia.com/soft.asp?id=1034
            簡(jiǎn)體中文版:
            http://www.nengxia.com/soft.asp?id=15
            繁體中文版:
            http://www.nengxia.com/soft.asp?id=16

            Effective STL
            http://www.nengxia.com/soft.asp?id=54

            c++ 標(biāo)準(zhǔn)庫(kù)
            http://www.nengxia.com/soft.asp?id=47

            Exception c++
            中文版:http://www.nengxia.com/soft.asp?id=1035
            英文版:http://www.nengxia.com/soft.asp?id=18

            More Excetption c++
            英文版:http://www.nengxia.com/soft.asp?id=20

            C++ Coding Standards:
            http://www.nengxia.com/soft.asp?id=114

            STL輕松入門
            http://www.nengxia.com/soft.asp?id=162

            c/c++標(biāo)準(zhǔn)函數(shù)庫(kù) 中文版
            http://www.nengxia.com/soft.asp?id=641

            the design and evolution of c++
            英文版:http://nengxia.com/soft.asp?id=1042

            高質(zhì)量C++編程指南
            http://www.nengxia.com/soft.asp?id=1043



            posted @ 2007-10-24 16:45 c++ 學(xué)習(xí) 閱讀(11476) | 評(píng)論 (8)編輯 收藏
             
            程序員常常需要實(shí)現(xiàn)回調(diào)。本文將討論函數(shù)指針的基本原則并說(shuō)明如何使用函數(shù)指針實(shí)現(xiàn)回調(diào)。注意這里針對(duì)的是普通的函數(shù),不包括完全依賴于不同語(yǔ)法和語(yǔ)義規(guī)則的類成員函數(shù)(類成員指針將在另文中討論)。

            聲明函數(shù)指針

            ??? 回調(diào)函數(shù)是一個(gè)程序員不能顯式調(diào)用的函數(shù);通過(guò)將回調(diào)函數(shù)的地址傳給調(diào)用者從而實(shí)現(xiàn)調(diào)用。要實(shí)現(xiàn)回調(diào),必須首先定義函數(shù)指針。盡管定義的語(yǔ)法有點(diǎn)不可思議,但如果你熟悉函數(shù)聲明的一般方法,便會(huì)發(fā)現(xiàn)函數(shù)指針的聲明與函數(shù)聲明非常類似。請(qǐng)看下面的例子:

            void f();// 函數(shù)原型

            上面的語(yǔ)句聲明了一個(gè)函數(shù),沒(méi)有輸入?yún)?shù)并返回void。那么函數(shù)指針的聲明方法如下:

            void (*) ();

            ??? 讓我們來(lái)分析一下,左邊圓括弧中的星號(hào)是函數(shù)指針聲明的關(guān)鍵。另外兩個(gè)元素是函數(shù)的返回類型(void)和由邊圓括弧中的入口參數(shù)(本例中參數(shù)是空)。注意本例中還沒(méi)有創(chuàng)建指針變量-只是聲明了變量類型。目前可以用這個(gè)變量類型來(lái)創(chuàng)建類型定義名及用sizeof表達(dá)式獲得函數(shù)指針的大小:

            // 獲得函數(shù)指針的大小
            unsigned psize = sizeof (void (*) ());?

            // 為函數(shù)指針聲明類型定義
            typedef void (*pfv) ();

            pfv是一個(gè)函數(shù)指針,它指向的函數(shù)沒(méi)有輸入?yún)?shù),返回類行為void。使用這個(gè)類型定義名可以隱藏復(fù)雜的函數(shù)指針語(yǔ)法。

            指針變量應(yīng)該有一個(gè)變量名:

            void (*p) (); //p是指向某函數(shù)的指針

            ??? p是指向某函數(shù)的指針,該函數(shù)無(wú)輸入?yún)?shù),返回值的類型為void。左邊圓括弧里星號(hào)后的就是指針變量名。有了指針變量便可以賦值,值的內(nèi)容是署名匹配的函數(shù)名和返回類型。例如:

            void func()?
            {
            /* do something */
            }?
            p = func;?

            p的賦值可以不同,但一定要是函數(shù)的地址,并且署名和返回類型相同。

            傳遞回調(diào)函數(shù)的地址給調(diào)用者

            ??? 現(xiàn)在可以將p傳遞給另一個(gè)函數(shù)(調(diào)用者)- caller(),它將調(diào)用p指向的函數(shù),而此函數(shù)名是未知的:

            void caller(void(*ptr)())
            {
            ptr(); /* 調(diào)用ptr指向的函數(shù) */?
            }
            void func();
            int main()
            {
            p = func;?
            caller(p); /* 傳遞函數(shù)地址到調(diào)用者 */
            }

            ??? 如果賦了不同的值給p(不同函數(shù)地址),那么調(diào)用者將調(diào)用不同地址的函數(shù)。賦值可以發(fā)生在運(yùn)行時(shí),這樣使你能實(shí)現(xiàn)動(dòng)態(tài)綁定。

            調(diào)用規(guī)范

            ??? 到目前為止,我們只討論了函數(shù)指針及回調(diào)而沒(méi)有去注意ANSI C/C++的編譯器規(guī)范。許多編譯器有幾種調(diào)用規(guī)范。如在Visual C++中,可以在函數(shù)類型前加_cdecl,_stdcall或者_(dá)pascal來(lái)表示其調(diào)用規(guī)范(默認(rèn)為_(kāi)cdecl)。C++ Builder也支持_fastcall調(diào)用規(guī)范。調(diào)用規(guī)范影響編譯器產(chǎn)生的給定函數(shù)名,參數(shù)傳遞的順序(從右到左或從左到右),堆棧清理責(zé)任(調(diào)用者或者被調(diào)用者)以及參數(shù)傳遞機(jī)制(堆棧,CPU寄存器等)。

            ??? 將調(diào)用規(guī)范看成是函數(shù)類型的一部分是很重要的;不能用不兼容的調(diào)用規(guī)范將地址賦值給函數(shù)指針。例如:

            // 被調(diào)用函數(shù)是以int為參數(shù),以int為返回值
            __stdcall int callee(int);?

            // 調(diào)用函數(shù)以函數(shù)指針為參數(shù)
            void caller( __cdecl int(*ptr)(int));?

            // 在p中企圖存儲(chǔ)被調(diào)用函數(shù)地址的非法操作
            __cdecl int(*p)(int) = callee; // 出錯(cuò)


            ??? 指針p和callee()的類型不兼容,因?yàn)樗鼈冇胁煌恼{(diào)用規(guī)范。因此不能將被調(diào)用者的地址賦值給指針p,盡管兩者有相同的返回值和參數(shù)列。?
            posted @ 2006-11-18 13:55 c++ 學(xué)習(xí) 閱讀(212) | 評(píng)論 (0)編輯 收藏
             
            本題目是懶豬一字一字敲上電腦的,轉(zhuǎn)載請(qǐng)尊重懶豬的勞動(dòng)成果,注明轉(zhuǎn)自懶豬的窩窩http://spaces.msn.com/davidblogs/,資源共享,謝謝合作。
            懶豬稍后給出自己做的參考解答,希望能和大家多多交流。
            ?
            編程環(huán)境:VC++6
            考試時(shí)間:3小時(shí)
            Problem A.Fibonacci
            Input:????????? ?fib.in
            Output:??????? Standard Output
            Time limit:??? ?5 second
            Memory limit: 64 megabytes
            Offerd by :?? http://spaces.msn.com/davidblogs/
            ?
            The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurrence:
            F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2
            Write a program to calculate the Fibonacci Numbers.
            ?
            Input
            The input file contains a number n and you are expected to calculate Fn.(0<=n<=30)

            Output
            Print a number Fn on a separate line,which means the nth Fibonacci Number.
            ?
            Example
            fib.in?????? Standard Output
            1??????????? 1
            2??????????? 1
            3??????????? 2
            4??????????? 3
            5??????????? 5
            6??????????? 8
            ?

            Problem B.WERTYU
            Input:????????? ?wertyu.in
            Output:?????? ? Standard Output
            Time limit:???? ?5 second
            Memory limit:? 64 megabytes
            Offerd by :?? http://spaces.msn.com/davidblogs/
            ?
            A common typing error is to place the hands on the keyboard one row to the right of the correct position.So "Q" is typed as "W" and "J" is typed as "K" and so on.You are to decode a message typed in this manner.
            ?
            ` 1 2 3 4 5 6 7 8 9 0 - = BackSp
            Tab Q W E R T Y U I O P [ ] \
            A S D F G H J K L ; ' Enter
            Z? X? C? V? B? N? M? ,? .? /
            Control Alt? Space? Alt Control
            ?
            Input
            The input file consist of several lines of text.Each line may contain digits,spaces,upper case letters(except Q,A,Z),or punctuation shown above(except back-quote(') which is left to the key "1").Keys labelled with words [Tab,BackSp,Control,etc.] are not represented in the input.
            ?
            Output
            You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above.Spaces in the input should be echoed in the output.
            ?
            Example
            wertyu.in??????????????????? ?Standard Output
            O S, GOMR YPFSU/??????? I AM FINE TODAY.
            ?
            ?
            Problem C.String Matching
            Input:????????? ??matching.in
            Output:?????? ? Standard Output
            Time limit:???? ?5 second
            Memory limit:? 64 megabytes
            Offerd by :?? http://spaces.msn.com/davidblogs/
            ?
            Finding all occurrences of a pattern in a text is a problem that arises frequently in text-editing programs.Typically,the text is a document being edited,and the pattern searched for is a particular word supplied by the user.
            ?
            We assume that the text is an array T[1..n] of length n and that the pattern is an array P[1..m] of length m<=n.We further assume that the elements of P and T are all alphabets(∑={a,b...,z}).The character arrays P and T are often called strings of characters.
            ?
            We say that pattern P occurs with shift s in the text T if 0<=s<=n and T[s+1..s+m] = P[1..m](that is if T[s+j]=P[j],for 1<=j<=m).
            ?
            If P occurs with shift s in T,then we call s a valid shift;otherwise,we call s a invalid shift.
            Your task is to calculate the number of vald shifts for the given text T and pattern P.
            ?
            Input
            In the input file,there are two strings T and P on a line,separated by a single space.You may assume both the length of T and P will not exceed 10^6.
            ?
            Output
            You should output a number on a separate line,which indicates the number of valid shifts for the given text T and pattern P.
            ?
            Example
            matching.in????? ?Standard Output
            aaaaaa a????????? ??6
            abababab abab?? 3
            abcdabc abdc??? ?0
            ?
            Problem D.Exponential Form
            Input:????????? ? form.in
            Output:?????????Standard Output
            Time limit:????? 5 second
            Memory limit:? 64 megabytes
            Offerd by :?? http://spaces.msn.com/davidblogs/
            ?
            Every positive number can be presented by the exponential form.For example,
            137 = 2^7 + 2^3 + 2^0
            Let's present a^b by the form a(b).Then 137 is presented by 2(7)+2(3)+2(0).
            Since 7 = 2^2 + 2 + 2^0 and 3 = 2 + 2^0 , 137 is finally presented by 2(2(2)+2+2(0))+2(2+2(0))+2(0).
            ?
            Given a positive number n,your task is to present n with the exponential form which only contains the digits 0 and 2.
            ?
            Input
            The input file contains a positive integer n (n<=20000).
            ?
            Output
            You should output the exponential form of n an a single line.Note that,there should not be any additional white spaces in the line.
            ?
            Example
            form.in
            137
            Stardard Output
            2(2(2)+2+2(0))+2(2+2(0))+2(0)
            form.in
            1315
            Stardard Output
            2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
            posted @ 2006-03-31 19:16 c++ 學(xué)習(xí) 閱讀(918) | 評(píng)論 (0)編輯 收藏
             
            我是看了msdn后,感覺(jué)還是很簡(jiǎn)單的,只要知道三個(gè)東西
            va_arg, va_start, va_end
            va_arg:
            typeva_arg(
            ?? va_listarg_ptr,
            ?? type
            );

            va_arg returns the current argument; va_start and va_end do not return values

            The va_arg, va_end, and va_start macros provide a portable way to access the arguments to a function when the function takes a variable number of arguments. Two versions of the macros are available: The macros defined in STDARG.H conform to the ANSI C standard, and the macros defined in VARARGS.H are compatible with the UNIX System V definition. The macros are:

            The ANSI C standard macros, defined in STDARG.H, are used as follows:

            • All required arguments to the function are declared as parameters in the usual way. va_dcl is not used with the STDARG.H macros.
            • va_start sets arg_ptr to the first optional argument in the list of arguments passed to the function. The argument arg_ptr must have va_list type. The argument prev_param is the name of the required parameter immediately preceding the first optional argument in the argument list. If prev_param is declared with the register storage class, the macro's behavior is undefined. va_start must be used before va_arg is used for the first time.
            • va_arg retrieves a value of type from the location given by arg_ptr and increments arg_ptr to point to the next argument in the list, using the size of type to determine where the next argument starts. va_arg can be used any number of times within the function to retrieve arguments from the list.

            The example:

            //?crt_va.c
            /*?The?program?below?illustrates?passing?a?variable
            ?*?number?of?arguments?using?the?following?macros:
            ?*??????va_start????????????va_arg??????????????va_end
            ?*??????va_list?????????????va_dcl?(UNIX?only)
            ?
            */


            #include?
            <stdio.h>
            #define?ANSI????????????/*?Comment?out?for?UNIX?version?????*/
            #ifdef?ANSI?????????????
            /*?ANSI?compatible?version??????????*/
            #include?
            <stdarg.h>
            int?average(?int?first,??);
            #else???????????????????/*?UNIX?compatible?version??????????*/
            #include?
            <varargs.h>
            int?average(?va_list?);
            #endif

            int?main(?void?)
            {
            ???
            /*?Call?with?3?integers?(-1?is?used?as?terminator).?*/
            ???printf(?
            "Average?is:?%d\n",?average(?2,?3,?4,?-1?)?);

            ???
            /*?Call?with?4?integers.?*/
            ???printf(?
            "Average?is:?%d\n",?average(?5,?7,?9,?11,?-1?)?);

            ???
            /*?Call?with?just?-1?terminator.?*/
            ???printf(?
            "Average?is:?%d\n",?average(?-1?)?);
            }


            /*?Returns?the?average?of?a?variable?list?of?integers.?*/
            #ifdef?ANSI?????????????
            /*?ANSI?compatible?version????*/
            int?average(?int?first,??)
            {
            ???
            int?count?=?0,?sum?=?0,?i?=?first;
            ???va_list?marker;

            ???va_start(?marker,?first?);?????
            /*?Initialize?variable?arguments.?*/
            ???
            while(?i?!=?-1?)
            ???
            {
            ??????sum?
            +=?i;
            ??????count
            ++;
            ??????i?
            =?va_arg(?marker,?int);
            ???}

            ???va_end(?marker?);??????????????
            /*?Reset?variable?arguments.??????*/
            ???
            return(?sum???(sum?/?count)?:?0?);
            }

            #else???????/*?UNIX?compatible?version?must?use?old-style?definition.??*/
            int?average(?va_alist?)
            va_dcl
            {
            ???
            int?i,?count,?sum;
            ???va_list?marker;

            ???va_start(?marker?);????????????
            /*?Initialize?variable?arguments.?*/
            ???
            for(?sum?=?count?=?0;?(i?=?va_arg(?marker,?int))?!=?-1;?count++?)
            ??????sum?
            +=?i;
            ???va_end(?marker?);??????????????
            /*?Reset?variable?arguments.??????*/
            ???
            return(?sum???(sum?/?count)?:?0?);
            }

            #endif


            最主要的是average 函數(shù)
            開(kāi)始時(shí)申明一個(gè)va_list marker
            后來(lái)調(diào)用va_start(marker);
            再后來(lái)調(diào)用va_arg(marker, int)
            最后結(jié)束時(shí)調(diào)用va_end(marker):

            posted @ 2006-03-21 12:39 c++ 學(xué)習(xí) 閱讀(758) | 評(píng)論 (0)編輯 收藏
             

            ?

            給出一個(gè)前序遍歷,給出一個(gè)中序遍歷,要求把樹(shù)輸出
            給出算法答案如下:
            main()
            {
            Datatype?preorder[n],?inorder[n];
            Struct?link
            * BT;
            if (n? > ? 0 )
            BT?
            = ?creatBT( 0 ,?n - 1 ,? 0 ,?n? - ? 1 );
            return (BT);
            }


            struct ?link * ?createBT( int ?prestart,? int ?preend,? int ?instart,? int ?inend)
            {
            p?
            = ?( struct ?link * )malloc( sizeof ( struct ?link);
            p
            -> lchild? = ? null ;
            p
            -> rchild? = ? null ;
            p
            -> data? = ?preorder[prestart];
            if (prestart? > ?preend)
            {?
            ??
            for ( int ?i? = ?instart;?inorder[i]? != ?preorder[start];?i ++ );
            ?
            if (i? > ?instart)
            ???p
            -> lchild? = ?createBT(prestart? + ? 1 ,?prestart - ?instart? + ? 1 ,?instart,?i? - ? 1 );
            ?
            if (i? < ?inend)
            ??p
            -> rchild? = ?createBT(prestart? - ?instart? + ?i? + ? 1 ,?preend,?i? + ? 1 ,?inend);????????
            }
            ??
            ?
            return ?(p):
            }

            posted @ 2006-03-21 10:55 c++ 學(xué)習(xí) 閱讀(683) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題
            共3頁(yè): 1 2 3 
             
            青青草国产精品久久久久| 日韩精品久久久久久久电影| 亚洲人成伊人成综合网久久久 | 久久青草国产手机看片福利盒子| 精品无码久久久久国产| 99久久婷婷国产一区二区| 亚洲欧美日韩久久精品| 激情伊人五月天久久综合| 免费一级欧美大片久久网| 久久精品无码午夜福利理论片| 四虎国产精品免费久久5151 | 精品99久久aaa一级毛片| 久久这里都是精品| 狠狠久久综合| 久久亚洲国产精品一区二区| 一级做a爰片久久毛片免费陪| 久久国产精品久久精品国产| 人人妻久久人人澡人人爽人人精品| 色婷婷综合久久久久中文一区二区| 国产成人久久精品区一区二区| 无码任你躁久久久久久老妇App| 韩国三级中文字幕hd久久精品| 久久er国产精品免费观看2| 久久精品国产亚洲AV不卡| 国内精品久久久久久不卡影院 | 中文精品99久久国产| 91精品观看91久久久久久| 国产精品久久自在自线观看| 久久久久久精品免费看SSS| 久久久久久国产精品无码下载| 精品国产乱码久久久久久郑州公司 | 精品久久久久中文字| 亚洲国产精品一区二区久久| 国内精品伊人久久久久AV影院| 无码人妻精品一区二区三区久久久| 久久国产AVJUST麻豆| 超级碰碰碰碰97久久久久| 人人妻久久人人澡人人爽人人精品| 久久国内免费视频| 色欲久久久天天天综合网| 亚洲AV无码久久精品成人|