½«Àà³ÉÔ±º¯ÊýÓÃ×ö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*) &
Ïà¹ØÎĵµ£º
C/C++ÊÇ×îÖ÷ÒªµÄ±à³ÌÓïÑÔ¡£ÕâÀïÁгöÁË50ÃûÓÅÐãÍøÕ¾ºÍÍøÒ³Çåµ¥£¬ÕâЩÍøÕ¾Ìṩc/c++Ô´´úÂë¡£Õâ·ÝÇåµ¥ÌṩÁËÔ´´úÂëµÄÁ´½ÓÒÔ¼°ËüÃǵÄС˵Ã÷¡£ÎÒÒѾ¡Á¦°üÀ¨×î¼ÑµÄC/C++Ô´´úÂëµÄÍøÕ¾¡£Õâ²»ÊÇÒ»¸öÍêÕûµÄÇåµ¥£¬ÄúÓн¨Òé¿ÉÒÔÁªÏµÎÒ£¬ÎÒ½«»¶ÓÄúµÄ½¨Ò飬ÒÔ½øÒ»²½¼ÓÇ¿Õâ·½ÃæµÄÇåµ¥¡£
1¡¢http://snippets.dzone.com/tag/c/ --ÊýÒÔǧ¼Æ ......
ÓÃvc6н¨ÁËÒ»¸öwin32µÄ¿ØÖÆ̨³ÌÐò£¬µ÷ÊÔÒ»¸öÖ±½Ó²åÈëÅÅÐòµÄС³ÌÐò£¬Îļþ¶¨ÒåΪ.cÎļþ£¬¶ø²»ÊÇÒ»°ãʹÓõÄ.cppÎļþ£¬´úÂë¶ÎÈçÏ£º
#include <stdio.h>
void inst(int* x,int n)
{
int i,j,t;
for(i=1; i<n; i++) /* i±íʾ²åÈë´ÎÊý£¬¹²½øÐÐn-1´Î²åÈë*/
{
t = x[i];
for(j=i-1; j> ......
PCÖ®¸¸C. ThackerÈÙ»ñ2009ÄêͼÁé½±
2010-03-10 01:21 | 3110´ÎÔĶÁ | ¡¾ÒÑÓÐ16ÌõÆÀÂÛ¡¿·¢±íÆÀÂÛ
¹Ø¼ü´Ê£ºÐÂÎÅ×ÊѶ | ¸ÐлliujiangCEµÄÌṩ | ÊÕ²ØÕâƪ×ÊѶ
¸ù¾ÝACM¹Ù·½ÍøÕ¾3ÔÂ9ÈÕ·¢²¼µÄÏûÏ¢£¬2009ÄêͼÁé½±ÊÚÓèÁËÏÖ´úPCÖ®¸¸Charles Thacker£¬ÒÔ±íÕÃËû¶ÔµÚһ̨ÏÖ´ú¸öÈ˼ÆËã»úXerox PARC Altoµ ......
CÓïÑÔÖУº
extern £ºextern£¨ÍⲿÒýÓã©¿ÉÒÔÖÃÓÚ±äÁ¿»òÕߺ¯ÊýÇ°£¬ÒÔ±êʾ±äÁ¿»òº¯ÊýµÄ¶¨ÒåÔÚ±ðµÄÎļþÖУ¬ÔÚÒ»¸öÎļþÖÐÓõ½µÄexternÕâЩ±äÁ¿»òº¯ÊýÊÇÍâÀ´µÄ£¬²»ÊDZ¾Îļþ¶¨ÒåµÄ£¬Ìáʾ±àÒëÆ÷Óöµ½´Ë±äÁ¿ºÍº¯ÊýʱÔÚÆäËûÄ£¿éÖÐÑ°ÕÒÆ䶨Òå¡£×¢Ò⣬ֻÓÐÆäËûÎļþÖеÄÈ«¾Ö±äÁ¿²ÅÄܱ»ÆäËûÎļþËùextern¡£
extern int val;
×¢£º
  ......
±¾ÎÄÊÇд¸ø 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Ö ......