ºìÁªLinuxÃÅ»§
Linux°ïÖú

ѧϰC++±à³ÌÓïÑÔµÄ×î´óÄѶÈÊÇʲô

·¢²¼Ê±¼ä:2006-05-03 12:09:15À´Ô´:ºìÁª×÷Õß:°®µÄ±ßÔµ
À§ÄѶÈÖ®Ò»

¡°C++ ÊǸöÄÑѧÒ×ÓõÄÓïÑÔ¡±£¬Õâ¾ä»°ÏàÐźܶàÈ˶¼ÐÄÓÐÆÝÆÝ¡£C++µÄѧϰÄѶȣ¬Ò»ÔÚÓÚÓïÑÔ±¾ÉíÌ«¶àµÄ¡°Ä»¡±£¬ÁíÒ»¸ö¾ÍÔÚÓÚ "paradigm shift" £¨Ë¼¿¼Ä£Ê½µÄÒÆת£©¡£

´«Í³ÓïÑÔÈç C, Pascal, Basic, Fortran...£¬³ýÁËÄ£Ñù¿´ÆðÀ´ÉÔÓв»Í¬£¬»ù±¾É϶¼ÊǺ¯Ê½ call À´ call È¥£¬´óͬСÒ죬ºÜÈÝÒ×ÕÆÎÕ¡£ÄãÏë×öµÄ¶¯×÷£¬ÔÚ code Öж¼¿´µÃÒ»Çå¶þ³þ¡£ÄãËù¿´²»µ½µÄ£¬Ò²²»¹ý¾ÍÊDZàÒëÆ÷ΪÄãµÄº¯Ê½¼ÓÉÏÓÃÒÔ´¦Àí¶ÑµþµÄһС¶ÎÂ루prologue ºÍ epilogue£©£¬ÕâһС¶ÎÂë»ù±¾ÉÏ×öµÄÊÇ housekeeping ¹¤×÷£¬Äãû¿´µ½Ò²Ã»ÓйØϵ£¬²¢²»Ó°ÏìÄã¶Ô³ÌʽÂß¼­µÄ˼¿¼¡£

C++ ²»Ò»Ñù£¬C++ ÓÐÌ«¶àºÍ³ÌʽÂß¼­Ï¢Ï¢Ïà¹ØµÄ¶¯×÷ÊDZàÒëÆ÷ΪÎÒÃǼÓÉÏÈ¥µÄ¡£»»¾ä»°Ëµ C++ ±àÒëÆ÷ΪÎÒÃÇ¡°¼ÓÂ롱¡£Èç¹û²»Ê¶ÇåÕâÒ»½Ú£¬Ñ§Ï°C++ ÓÐÈçÎíÀï¿´»¨£¬Îí·ÇÎí£¬»¨·Ç»¨¡£

±àÒëÆ÷ΪÎÒÃÇµÄ C++ ³Ìʽ¼ÓÁËʲôÂëÄØ£¿ºÜ¶à£¡Îï¼þµ®Éúʱ ctor »á±»»½Æð£¬Îï¼þËÀÍöʱ dtor »á±»»½Æð£¬ÕⶼÊǼÓÂëµÄ½á¹û¡£ctor ÖÐÉ趨vtpr ºÍ vtbl£¬ÕâÒ²ÊǼÓÂëµÄ½á¹û¡£new µ¥Ò»Îï¼þʱ»á²úÉú memory block cookie£¬new Îï¼þÕóÁÐʱ»á²úÉúÒ»¸öÄÚ²¿½á¹¹¼Ç¼×Å object size ºÍ class ctor...£¬ÕâÒ²¶¼ÊDz¼Ä»ºóµÄ¹¤×÷¡£¿ÉÒÔ˵£¬³ÌʽÂëÖп´²»µ½¶øÈ´±ØÐëÍê³ÉµÄËùÓÐÓë³ÌʽÂß¼­ÓйصĶ¯×÷£¬Í³Í³¶¼ÊÇ C++ ±àÒëÆ÷¼ÓÂëºóµÄ½á¹û¡£

µ±¡°¼Ì³Ð¡±·¢Éú£¬Õû¸öÇé¿ö±äµÃÉÔ΢¸´ÔÓÆðÀ´¡£¡°¶àÖؼ̳С±ÓÖ¸ü¸´ÔÓһЩ£¬¡°ÐéÄâ¼Ì³Ð¡±ÓÖÔÙ¸ü¸´ÔÓһЩ¡£

ÕâЩ²¼Ä»ºóµÄÖ÷Ì⣬ͳ¿É¹éÀàΪËùνµÄ C++ object model£¨Îï¼þÄ£ÐÍ£©¡£Èç¹û²»ÖªµÀÕâЩµ×²ã»úÖÆ£¬Äã¾ÍÖ»Äܹ»°Ñ "make destructors virtual in base classes"»ò "never treat arrays polymorphically"ÕâÀà¹æÔòÓ²±³ÏÂÀ´£¬È´²»Ã÷°×ËüµÄµÀÀí¡£ÓÃÒ»Ñù¶«Î÷£¬È´²»Ã÷°×ËüµÄµÀÀí£¬ÁÖÓïÌÃÈçÊÇ˵£º¡°²»¸ßÃ÷¡±¡£Ö»ÖªµÀ how£¬²»ÖªµÀ why¡£

À§ÄѶÈÖ®¶þ

C++ µÄµÚ¶þ¸öѧϰÄѶÈÔÚÓÚ "paradigm shift"£¨Ë¼¿¼Ä£Ê½µÄÒÆת£©¡£±ð˵×Ô¼ºÉè¼Æclasses ÁË£¬¹âʹÓñðÈ˵Äclasses£¬¾Í¶¼ÊÇÒ»ÖÖ˼¿¼Ä£Ê½ºÍÐÐΪģʽµÄÒÆת¡£MFC£¨»ò OWL »ò VCL£©programmer ±ØÈ»Äܹ»ÁìÂÔ²¢Ìå»áÆäÖеÄÒâ˼¡£

ʹÓÃËùνµÄ application framework£¨Ò»ÖÖ´óÐ͵ġ¢Äý¾ÛÐÔÇ¿µÄ¡¢ÓÐ×ÅÎï¼þµ¼Ïò¹«¹²»ù´¡½¨ÉèµÄ class library£©£¬ÄãµÄÂëºÍ framework Ö®¼ä¾¿¾¹ÊÇÔõÑùµÄ¹ØϵÄØ£¿framework ÌṩµÄÒ»´ó¶Ñ¿É¸ÄдµÄÐéÄ⺯ʽµÄÒâÒåÓë¼ÛÖµ¾¿¾¹ÔÚÄÄÀïÄØ£¿ÎªÊ²Ã´ framework ËùÉè¼ÆµÄÖÖÖÖÃÀºÃÐÔÖÊÒÔ¼°¸÷ʽ¸÷ÑùµÄÑÝËã·¨¾¹È»¿ÉÒÔÊ©ÐÐÓÚÎÒÃÇ×Ô¼ºÉè¼ÆµÄ class types ÉíÉÏÄØ£¿framework ±»Éè¼Æʱ£¬Ò²²¢²»ÖªµÀÎÒÃǵĴæÔÚ¡£ÕâÕýÊÇÎï¼þµ¼ÏòÖеĶàÐÍ£¨polymorphism£©µÄÍþÁ¦¡£

ÉÔÔçËù˵µÄ C++ Îï¼þÄ£ÐÍ£¬Æ«Êô³ÌʽÉè¼ÆµÄµÍ²ãÃ棻ÕâÀïËù˵µÄ˼¿¼Ä£Ê½ÒÆת£¬ÔòÊdzÌʽÉè¼ÆµÄ¸ß²ãÃæ¡£Äܹ»°ÑÐÂ˼άģʽµÄÍþÁ¦·¢»ÓµÃ×îÁÜÀ쾡Öµģ¬µ±ÍÆÎï¼þµ¼ÏòµÄ polymorphism£¨¶àÐÍ£©ºÍ generalization£¨·ºÐÍ£©¡£Èç¹ûÄãûÓÐʹÓÃÕâÁ½ÏîÌØÐÔ£¬µÈÓÚÈë C++ ±¦É½È´¿ÕÊÖ¶ø¹é¡£

·´¸²Ä¥Á¶£¬Ñ­»·Õðµ´

ÏëÏñ C++ ÊÇÒ»°ÑÓÃÀ´½â¾ö³ÌʽÎÊÌâµÄµ¶£¬ÒªËü¼áéí£¬ÒªËü·æÀû£¬¾Í±ØÐë¾­¹ý¶à´ÎµÄ»Ø»ð£¬ÔÚ¸ßÈȺÍÖèÀäÖ®¼ä----Á¶¡£

³õѧ C++ Óï·¨£¨syntax£©Ö®ºó£¬ÄãÓ¦¸Ã¾¡¿ì³¢ÊÔÌåÑé polymorphism£¨´óÖ¶øÑÔÒ²¾ÍÊÇÐéÄ⺯ʽµÄÔËÓã©¡£µÈµ½¶Ô OOP µÄ¾«ÉñÓÐÁË´ó¾ÖÕƿصÄÄÜÁ¦£¬µ«¶Ô C++ µÄÐí¶àСϸ½Ú²»ÉõÇå³þ£¬¾ÍÊǻص½C++ Îï¼þÄ£ÐÍ Á¶µÄʱ»ú¡£

³É³¤£¬ÊÇÔڸ߽ף¨polymorphism£©ºÍµÍ½×£¨object model£©Ö®¼ä·´¸²Õðµ´£¬²ÅÄܹ»Õðµ´µ½¸ü¸ßµÄλ½×£¬¶ø²»ÊÇƽƽӹӹÓÚÖнף¨C++ syntax£©µÄһ̲ËÀË®¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 4 ÌõÆÀÂÛ

  1. ϲ´óÆÕ±¼ ÓÚ 2014-02-23 12:31:51·¢±í:

    ±¾È˹ýÈ¥¡¢ÏÖÔÚÒÔ¼°½«À´¶¼²»ÈÏʶ¥Ö÷£¬ÇÒ×Ô¹ÅÒÔÀ´ÓëÂ¥Ö÷ÎÞÀûÒæ¹Øϵ¡£Â¥Ö÷±íÊöÖ®ÊÂÓë±¾ÈËÎÞ¹Ø.

  2. yu-ge ÓÚ 2014-02-17 14:25:30·¢±í:

    ÔÝʱ¿´²»¶®

  3. zhengf7513 ÓÚ 2014-02-04 00:04:22·¢±í:

    ²»¶®

  4. qxfsy ÓÚ 2014-01-03 03:46:55·¢±í:

    ÓÐÒ»¶¨µÄµÀÀí