½«Àà³ÉÔ±º¯ÊýÓÃ×öC»Øµ÷º¯Êý
½«Àà³ÉÔ±º¯ÊýÓÃ×öC»Øµ÷º¯Êý Ìá³öÎÊÌ⣺ »Øµ÷º¯ÊýÊÇ»ùÓÚC±à³ÌµÄWindows SDKµÄ¼¼Êõ£¬²»ÊÇÕë¶ÔC++µÄ£¬³ÌÐòÔ±¿ÉÒÔ½«Ò»¸öCº¯ÊýÖ±½Ó×÷Ϊ»Øµ÷º¯Êý£¬µ«ÊÇÈç¹ûÊÔͼֱ½ÓʹÓÃC++µÄ³ÉÔ±º¯Êý×÷Ϊ»Øµ÷º¯Êý½«·¢Éú´íÎó£¬ÉõÖÁ±àÒë¾Í²»ÄÜͨ¹ý¡£·ÖÎöÔÒò£ºÆÕͨµÄC++³ÉÔ±º¯Êý¶¼Òþº¬ÁËÒ»¸ö´«µÝº¯Êý×÷Ϊ²ÎÊý£¬Ò༴“this”Ö¸Õ룬C++ͨ¹ý´«µÝÒ»¸öÖ¸Ïò×ÔÉíµÄÖ¸Õë¸øÆä³ÉÔ±º¯Êý´Ó¶øʵÏÖ³ÌÐòº¯Êý¿ÉÒÔ·ÃÎÊC++µÄÊý¾Ý³ÉÔ±¡£ÕâÒ²¿ÉÒÔÀí½âΪʲôC++ÀàµÄ¶à¸öʵÀý¿ÉÒÔ¹²Ïí³ÉÔ±º¯Êýµ«ÊÇÈ·Óв»Í¬µÄÊý¾Ý³ÉÔ±¡£ÓÉÓÚthisÖ¸ÕëµÄ×÷Óã¬Ê¹µÃ½«Ò»¸öCALLBACKÐ͵ijÉÔ±º¯Êý×÷Ϊ»Øµ÷º¯Êý°²×°Ê±¾Í»áÒòΪÒþº¬µÄthisÖ¸ÕëʹµÃº¯Êý²ÎÊý¸öÊý²»Æ¥Å䣬´Ó¶øµ¼Ö»ص÷º¯Êý°²×°Ê§°Ü½â¾ö·½°¸£ºÒ»,²»Ê¹ÓóÉÔ±º¯Êý£¬Ö±½ÓʹÓÃÆÕͨCº¯Êý£¬ÎªÁËʵÏÖÔÚCº¯ÊýÖпÉÒÔ·ÃÎÊÀàµÄ³ÉÔ±±äÁ¿£¬¿ÉÒÔʹÓÃÓÑÔª²Ù×÷·û(friend)£¬ÔÚC++Öн«¸ÃCº¯Êý˵Ã÷ΪÀàµÄÓÑÔª¼´¿É¡£ÕâÖÖ´¦Àí»úÖÆÓëÆÕͨµÄC±à³ÌÖÐʹÓûص÷º¯ÊýÒ»Ñù¡£¶þ,ʹÓþ²Ì¬³ÉÔ±º¯Êý£¬¾²Ì¬³ÉÔ±º¯Êý²»Ê¹ÓÃthisÖ¸Õë×÷ΪÒþº¬²ÎÊý£¬ÕâÑù¾Í¿ÉÒÔ×÷Ϊ»Øµ÷º¯ÊýÁË¡£¾²Ì¬³ÉÔ±º¯Êý¾ßÓÐÁ½´óÌص㣺ÆäÒ»£¬¿ÉÒÔÔÚûÓÐÀàʵÀýµÄÇé¿öÏÂʹÓã»Æä¶þ£¬Ö»ÄÜ·ÃÎʾ²Ì¬³ÉÔ±±äÁ¿ºÍ¾²Ì¬³ÉÔ±º¯Êý£¬²»ÄÜ·ÃÎʷǾ²Ì¬³ÉÔ±±äÁ¿ºÍ·Ç¾²Ì¬³ÉÔ±º¯Êý¡£ÓÉÓÚÔÚC++ÖÐʹÓÃÀà³ÉÔ±º¯Êý×÷Ϊ»Øµ÷º¯ÊýµÄÄ¿µÄ¾ÍÊÇΪÁË·ÃÎÊËùÓеijÉÔ±±äÁ¿ºÍ³ÉÔ±º¯Êý£¬Èç¹û×÷²»µ½ÕâÒ»µã½«²»¾ßÓÐʵ¼ÊÒâÒå¡£ÎÒÃÇͨ¹ýʹÓþ²Ì¬³ÉÔ±º¯Êý¶Ô·Ç¾²Ì¬³ÉÔ±º¯Êý°ü×°µÄ°ì·¨À´½â¾öÎÊÌâ¡£ÀàʵÀý¿ÉÒÔͨ¹ý¸½¼Ó²ÎÊý»òÈ«¾Ö±äÁ¿µÄ·½Ê½µÄ·½Ê½´«µÝµ½¾²Ì¬³ÉÔ±º¯ÊýÖС£·Ö±ð¾ÙÀýÈçÏ£º 1£¬²ÎÊý´«µÝµÄ·½Ê½ #include class TClassA { public: void Display(const char* text) { cout << text << endl; }; static void Wrapper_To_Call_Display(void* pt2Object, char* text); // more.... }; // ¾²Ì¬°ü×°º¯Êý£¬Äܹ»µ÷ÓóÉÔ±º¯ÊýDisplay(),±¾Éí×öΪ»Øµ÷º¯ÊýÀ´Ê¹Óà void TClassA::Wrapper_To_Call_Display(void* pt2Object, char* string) { // ÏÔʽÀàÐÍת»» TClassA* mySelf = (TClassA*) pt2Object; // µ÷ÓÃÆÕͨ³ÉÔ±º¯Êý mySelf->Display(string); } // »Øµ÷º¯ÊýµÄËÞÖ÷,ÔÚÕâÀï»Øµ÷Óú¯Êý±»Ê¹Óà void DoItA(void* pt2Object, void (*pt2Function)(void* pt2Object, char* text)) { // ʹÓûص÷º¯Êý pt2Function(pt2Object, "hi, i'm calling back using a argument ;-)"); } // Ö´ÐÐʾÀý void Callback_Using_Argument() { TClassA objA; DoItA((void*) &
Ïà¹ØÎĵµ£º
http://demonstyle.blog.163.com/blog/static/13143429020091010112159/
C/C++ ºêÏê½â
ic/c++ 2009-11-10 01:12:15 ÔĶÁ18 ÆÀÂÛ0 ×ֺţº´óÖÐС
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐÍ ......
×ÛÊö
¿´Ò»ÏÂÊäÈë²Ù×÷µÄÔÀí£¬
³ÌÐòµÄÊäÈ붼½¨ÓÐÒ»¸ö»º³åÇø£¬¼´ÊäÈ뻺³åÇø¡£Ò»´ÎÊäÈë¹ý³ÌÊÇÕâÑùµÄ£¬µ±Ò»´Î¼üÅÌÊäÈë½áÊøʱ»á½«ÊäÈëµÄÊý¾Ý´æÈëÊäÈ뻺³åÇø£¬¶øcinµÈÊäÈëÊä³öº¯ÊýÖ±½Ó´ÓÊä
È뻺³åÇøÖÐÈ¡Êý¾Ý¡£ÕýÒòΪcinµÈÊäÈëÊä³öº¯ÊýÊÇÖ±½Ó´Ó»º³åÇøÈ¡Êý¾ÝµÄ£¬ËùÒÔÓÐʱºòµ±»º³åÇøÖÐÓвÐÁôÊý¾Ýʱ£¬cinº¯Êý»áÖ±½ÓÈ¡µÃÕâЩ²ÐÁôÊý¾ ......
±¾ÎÄÊÇд¸ø gcc ÐÂÊÖµÄÈëÃÅÎÄÕ£¬ËùÒÔÄÚÈݱȽϼòµ¥¡£Èç¹ûÄãÖªµÀÏÂÃæ3ÌõÃüÁ¿ÉÒÔ±àÒëc++µÄ»°£¬¾Í²»ÓÃÔÚ±¾ÎÄÀË·Ñʱ¼äÁË
´úÂë:
g++ -Wall hellocpp.cpp
gcc -Wall hellocpp.cpp -lstdc++
gfortran -Wall hellocpp.cpp -lstdc++
×¢£º±¾ÎÄ×îаæÔÚwikiÖÐ http://wiki.ubuntu.org.cn/Gcchowto
£¨½¨Òé´ó¼ÒÖ±½Ó·ÃÎÊwikiÖ ......
static
DataManager
*
sharedDataManager
=
nil;
+
(DataManager
*
) sharedManager
{
@synchronized(self)
{
if
(sharedDataManager
==
nil)
&nb ......
CÊý×éµÄСÎÊÌâ
ÕâÀï˵µÄ¶¯Ì¬Êý×éÊÇ¿ÉÒÔ¸ù¾ÝÐèÒª¶¯Ì¬Ôö³¤Õ¼ÓÃÄÚ´æµÄÊý×飬±ÈÈç³ÌÐò³õʼ·ÖÅäÁË100¸öÔªËØ£¬¿ÉÊÇÔËÐÐÁËÒ»¶Îʱ¼äºóÇøÇø100¸ö¿Õ¼ä²»ÄÜÂú×ãÁË£¬ÏÖÔÚÐèÒª400¸ö£¬Ôõô°ìÄØ£»Äǿ϶¨ÐèÒªÔÙ¶îÍâ·ÖÅä300¸ö¡£
CÓïÑÔÓÐrealloc()º¯ÊýÀ´½â¾ö¿Õ¼äÀ©³äµÄÎÊÌ⣬µ«ÊDz»ÒªÍ ......