• <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++的新手,這些書籍都是很經典的。經典中的經典
            深度探索C++對象模型
            英文版: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
            簡體中文版:
            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++ 標準庫
            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++標準函數庫 中文版
            http://www.nengxia.com/soft.asp?id=641

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

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



            posted @ 2007-10-24 16:45 c++ 學習 閱讀(11460) | 評論 (8)編輯 收藏
             
            程序員常常需要實現回調。本文將討論函數指針的基本原則并說明如何使用函數指針實現回調。注意這里針對的是普通的函數,不包括完全依賴于不同語法和語義規則的類成員函數(類成員指針將在另文中討論)。

            聲明函數指針

            ??? 回調函數是一個程序員不能顯式調用的函數;通過將回調函數的地址傳給調用者從而實現調用。要實現回調,必須首先定義函數指針。盡管定義的語法有點不可思議,但如果你熟悉函數聲明的一般方法,便會發現函數指針的聲明與函數聲明非常類似。請看下面的例子:

            void f();// 函數原型

            上面的語句聲明了一個函數,沒有輸入參數并返回void。那么函數指針的聲明方法如下:

            void (*) ();

            ??? 讓我們來分析一下,左邊圓括弧中的星號是函數指針聲明的關鍵。另外兩個元素是函數的返回類型(void)和由邊圓括弧中的入口參數(本例中參數是空)。注意本例中還沒有創建指針變量-只是聲明了變量類型。目前可以用這個變量類型來創建類型定義名及用sizeof表達式獲得函數指針的大?。?br />
            // 獲得函數指針的大小
            unsigned psize = sizeof (void (*) ());?

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

            pfv是一個函數指針,它指向的函數沒有輸入參數,返回類行為void。使用這個類型定義名可以隱藏復雜的函數指針語法。

            指針變量應該有一個變量名:

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

            ??? p是指向某函數的指針,該函數無輸入參數,返回值的類型為void。左邊圓括弧里星號后的就是指針變量名。有了指針變量便可以賦值,值的內容是署名匹配的函數名和返回類型。例如:

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

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

            傳遞回調函數的地址給調用者

            ??? 現在可以將p傳遞給另一個函數(調用者)- caller(),它將調用p指向的函數,而此函數名是未知的:

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

            ??? 如果賦了不同的值給p(不同函數地址),那么調用者將調用不同地址的函數。賦值可以發生在運行時,這樣使你能實現動態綁定。

            調用規范

            ??? 到目前為止,我們只討論了函數指針及回調而沒有去注意ANSI C/C++的編譯器規范。許多編譯器有幾種調用規范。如在Visual C++中,可以在函數類型前加_cdecl,_stdcall或者_pascal來表示其調用規范(默認為_cdecl)。C++ Builder也支持_fastcall調用規范。調用規范影響編譯器產生的給定函數名,參數傳遞的順序(從右到左或從左到右),堆棧清理責任(調用者或者被調用者)以及參數傳遞機制(堆棧,CPU寄存器等)。

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

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

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

            // 在p中企圖存儲被調用函數地址的非法操作
            __cdecl int(*p)(int) = callee; // 出錯


            ??? 指針p和callee()的類型不兼容,因為它們有不同的調用規范。因此不能將被調用者的地址賦值給指針p,盡管兩者有相同的返回值和參數列。?
            posted @ 2006-11-18 13:55 c++ 學習 閱讀(210) | 評論 (0)編輯 收藏
             
            本題目是懶豬一字一字敲上電腦的,轉載請尊重懶豬的勞動成果,注明轉自懶豬的窩窩http://spaces.msn.com/davidblogs/,資源共享,謝謝合作。
            懶豬稍后給出自己做的參考解答,希望能和大家多多交流。
            ?
            編程環境:VC++6
            考試時間:3小時
            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++ 學習 閱讀(910) | 評論 (0)編輯 收藏
             
            我是看了msdn后,感覺還是很簡單的,只要知道三個東西
            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 函數
            開始時申明一個va_list marker
            后來調用va_start(marker);
            再后來調用va_arg(marker, int)
            最后結束時調用va_end(marker):

            posted @ 2006-03-21 12:39 c++ 學習 閱讀(748) | 評論 (0)編輯 收藏
             

            ?

            給出一個前序遍歷,給出一個中序遍歷,要求把樹輸出
            給出算法答案如下:
            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++ 學習 閱讀(676) | 評論 (0)編輯 收藏
            僅列出標題
            共3頁: 1 2 3 
             
            国产精品久久久久久久app| 777久久精品一区二区三区无码| 精品久久久久中文字幕一区| 精品久久久久久综合日本| 久久亚洲国产欧洲精品一| 午夜精品久久久内射近拍高清| 午夜精品久久久久久久无码| 久久午夜伦鲁片免费无码| 国产精品99久久久久久猫咪| 久久99精品久久久大学生| 2020最新久久久视精品爱| 亚洲国产成人久久综合一区77| 久久综合给合久久狠狠狠97色69| 国产精品久久久99| 少妇久久久久久久久久| 久久午夜综合久久| 久久精品国产精品青草app| 欧美激情一区二区久久久| 国产成人久久久精品二区三区| 香蕉久久夜色精品升级完成| 久久久久久极精品久久久| 国产午夜久久影院| 亚洲中文久久精品无码ww16| 无码任你躁久久久久久| 伊人久久免费视频| 国产精品久久久久久福利漫画| 99精品久久久久久久婷婷| 2021国产精品午夜久久| 精品久久久久久无码国产| 日本一区精品久久久久影院| 精品人妻久久久久久888| 久久夜色精品国产噜噜亚洲AV | 久久精品国产亚洲综合色| 久久狠狠爱亚洲综合影院| 波多野结衣久久一区二区| 日本精品久久久久影院日本| 国产精品成人久久久久三级午夜电影| 久久精品国产亚洲AV无码麻豆| 欧美熟妇另类久久久久久不卡| 久久综合精品国产二区无码| 国产成人精品免费久久久久|