Cº¯ÊýÖ¸ÕëµÄÓ÷¨
2008-06-05 12:38------------------------------------------------------------------------------------------------
º¯ÊýÖ¸Õëͨ³£ÓÃÀ´ÊµÏֻص÷£¬Æä»ù±¾Ó÷¨ÈçÏ£º
1¡¢¶¨Ò庯ÊýÖ¸ÕëÀàÐÍ
// ¶¨ÒåÒ»¸öÔÐÍΪint Fun( int a );µÄº¯ÊýÖ¸Õë
typedef int (*PTRFUN) ( int aPara );
2¡¢º¯ÊýÖ¸Õë±äÁ¿µÄ¶¨Òå
PTRFUN pFun; // pFun Ϊº¯ÊýÖ¸Õë±äÁ¿Ãû
int (*pFun2) ( int a ); // pFun2Ò²ÊǺ¯ÊýÖ¸Õë±äÁ¿Ãû
3¡¢º¯ÊýÖ¸Õë×÷Ϊº¯ÊýµÄ²ÎÊý´«µÝ
// ¶¨Ò廨µ÷º¯Êý
int CallBack( int a ){
return ++a;
}
// ¶¨Ò廨µ÷Õߺ¯Êý
void Caller( PTRFUN cb )
// void Caller( int (*cb) ( int ) ) // Ò²¿ÉÕâÑùÉêÃ÷
{
int nPara = 1;
int nRet = cb( nPara );
}
// ʹÓûص÷
void Test(){
Caller( CallBack ); // Ö±½ÓʹÓûص÷º¯Êý
PTRFUN cb = CallBack; // int (*cb) ( int ); cb = CallBack;
int nRet1 = cb( 99 ); // nRet1 = 100;
}
4¡¢º¯ÊýÖ¸ÕëµÄÖ¸ÕëʹÓÃ
// ¶¨Ò庯ÊýÖ¸ÕëµÄÖ¸Õë
typedef int (**PTRPTRFUN) ( int aPara );
// º¯ÊýÖ¸ÕëµÄÖ¸Õë×÷Ϊ²ÎÊý
void PtrCaller( PTRPTRFUN cb )
// void PtrCaller( PTRFUN* cb ) // Ö¸ÕëÉêÃ÷
// void PtrCaller( int (**cb) ( int ) ) // ÔÐÍÉêÃ÷
{
int nRet = (*cb)(999); // nRet = 1000;
}
// ʹÓú¯ÊýÖ¸ÕëµÄÖ¸Õë
void Test(){
PTRFUN cb = CallBack;
PtrCaller( &cb );
}
5¡¢º¯ÊýÖ¸ÕëÊý×éµÄʹÓÃ
// º¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå
PTRFUN fArray[10];
// int (*fArray[10]) ( int ); // ÔÐͶ¨Òå
for ( int i = 0; i < 10; i++ ){
fArray[i] = CallBack;
int nRet = fArray[i](i); // nRet = i+1;
}
6¡¢º¯ÊýÖ¸ÕëµÄ´óС
// ¼ÈÈ»½ÐÖ¸Õ룬ËùÒÔ¸úÆÕͨµÄÖ¸ÕëÒ»ÑùÔÚ32λϵͳÏ´óС¶¼Îª4
int nSz1 = sizeof(PTRFUN); // nSz1 = 4;
int nSz2 = sizeof(PTRPTRFUN); // nSz2 = 4;
×¢Ò⣺
±àÒëÆ÷´æÔÚ¶àÖÖÖÖµ÷Óù淶£¬
Ïà¹ØÎĵµ£º
#include
using namespace std;
typedef struct lnode
{
long sno;
char name[20];
struct lnode *next;
}LNode, *LinkList;
LinkList InitList()
{
LinkList head;
head = new LNode;
&nb ......
4.2 ¶à½Ç¶È±£Ö¤²âÊÔЧ¹û
¶ÔÓÚ´úÂëÖÊÁ¿ÒªÇóºÜ¸ßµÄÏîÄ¿À´Ëµ£¬½öÓа׺и²¸ÇÊÇÔ¶Ô¶²»¹»µÄ¡£°×ºÐ¸²¸Ç²»ÄÜ·¢ÏÖ´úÂëȱʧ£¬°×ºÐ¸²¸Ç»ùÓÚÏÖÓдúÂ룬Èç¹û´úÂë²»´æÔÚ£¬µ±È»²»ÄÜ·¢ÏÖ¡£ÎªÁ˼ì²â´úÂëȱʧ£¬ÐèÒªÈ˹¤¶Ô²âÊÔÊý¾Ý½øÐмì²é¡£°×ºÐ¸²¸ÇÒ²²»ÄÜ·¢ÏÖÓÃÀýδ·´Ó³¹¦ÄÜ¡£Èç¹ûÉè¼ÆÓÃÀýʱ£¬²âÊÔÔ±²»Á˽â´úÂëµÄ¹¦ÄÜ£¬Í ......
½ñÌ죬ÔÚÉè¼ÆC´úÂëµÄʱºò£¬Ïëµ½ÁËÒ»µã£¬ÏëÈÃB°üº¬A£¬²¢×ÔÓÉʹÓÃAµÄÍ·Îļþ£¬µ«ÊÇÈ´²»ÏëÈðüº¬BµÄCʹÓÃA£¬ÈÃAûÓÐȨÏÞÖ±½ÓʹÓÃʹÓÃC……ÈçÏÂͼ£º
²»ÖªµÀÓ¦¸ÃÔõô°ì¡£µ±Ê±ÐÄÏ룬Èç¹ûÊÇC++£¬Ê¹Óü̳У¬ºÜÁé»î¾ÍÄܸ㶨ÕâЩÊÂ
¸úͬÊÂÉÌÁ¿ÁËһϣ¬¶Ô·½¸ø³öÁË ......
ÔÚµ±½ñǶÈëʽ“ÎäÁÖ”ÖУ¬Á÷´«×ż¸±¾ÈËÈ˶¼Ïë͵ѧ¼¸ÕеÄCÓïÑÔµÄÎä¹¦ÃØ¼®¡£ÕâÐ©ÃØ¼®¶¼ÊÇ¿õÊÀÎäÑ§Ææ²ÅºÄ¾¡±ÏÉú¾«Á¦ËùÖø£¬²¿·ÖÃØ¼®Á÷¾ÊýÊ®ÔØÈÔ¾¾Ã²»Ë¥£¬ÈÃËüµÄÎÞÊýʵϰÕßÊÜÒæ·Ëdz¡£¡¡¡¡½ñÌ죬³ÐÃÉÎäÁÖ´ó»áËùÍÏ£¬ÔÚÕ⹫²¼Õ⼸±¾¹ØÓÚCµÄ“¾Ê锣¬Èøü¶àÈËʵϰ֮£¬Á·¾ÍÒ»Éí¾øÊÀµÄǶÈëʽCÓïÑԺù¦·ò¡£Î书à ......