C/C++ Ö¸Ïò×ÓÀà¶ÔÏóµÄ»ùÀàÖ¸Õë
ÓÐÈçϳÌÐò£º
//-----------------
class A
{
public:
A()
{
printf( "base A\r\n" );
}
virtual ~A()
{
printf( "base ~A\r\n" );
}
public:
virtual void VirtualFunc()
{
printf( "base VirtualFunc\r\n" );
};
void Func()
{
printf( "base Func\r\n" );
}
void F1()
{
printf( "base F1\r\n" );
}
protected:
private:
};
class B : public A
{
public:
B()
{
printf( "derive B\r\n" );
}
~B()
{
printf( "derive ~B\r\n" );
}
public:
virtual void VirtualFunc()
{
printf( "derive VirtualFunc\r\n" );
};
void Func()
{
printf( "derive Func\r\n" );
}
void G1()
{
printf( "derive G1\r\n" );
}
protected:
private:
};
ÔÚÕâÁ½¸öÀàÖУ¬×ÓÀàB ÖØдÁË »ùÀàµÄ Á½¸öº¯Êý£¬Ò»¸öÊÇÐ麯Êý£¬Ò»¸ö²»ÊÇÐ麯Êý¡£
1. Èç¹ûmainº¯ÊýÈçÏ£º
int main(int argc, int* argv[])
{
A* pA = new B; //»ùÀàÖ¸ÕëÖ¸Ïò×ÓÀà¶ÔÏó
pA->VirtualFunc();
pA->Func();
//pA->G1(); //³ö´í£º'G1' : is not a member of 'A'
delete( pA );
system("pause");
return 0;
}
ÔËÐнá¹ûÈçÏ£º
base A
derive B
derive VirtualFunc
base Func
derive ~B
base ~A
Ò²¾ÍÊÇ˵£¬Èç¹û×ÓÀàÖØдÁË»ùÀàµÄÐ麯Êý£¬ÄÇô¸ÃÖ¸Õ루»ùÀàÖ¸Õ룬µ«Ö¸ÏòÅÉÉúÀà¶ÔÏ󣩽«µ÷ÓÃ×ÓÀàµÄº¯Êý£»
¼´Ê¹×ÓÀàÖØдÁË×ÓÀàµÄ·ÇÐ麯Êý£¬¸ÃÖ¸ÕëÒ²²»»áµ÷ÓÃ×ÓÀàµÄº¯Êý¡£
2.
Èç¹ûmain º¯ÊýÈçÏ£º
int main(int argc, int* argv[])
{
B *pB = new B; //×ÓÀàÖ¸ÕëÖ¸Ïò×ÓÀà¶ÔÏó
pB->VirtualFunc();
pB->Func();
//pB->F1(); //ÕýÈ·£¬Êä³ö£ºbase F1¡£Çë×¢Ò⣺BÀàÊǹ«Óм̳ÐAÀà¡£¾ßÌå²Î¼û£ºC++µÄÈýÖּ̳з½Ê½
delete( pB );
system("pause");
return 0;
}
ÔòÔËÐнá¹ûÈçÏ£º
base A
derive B
derive VirtualFunc
derive Func
derive ~B
base ~A
¼´Èç¹ûÓÃ×ÓÀàÖ¸ÕëÖ¸Ïò×ÓÀà¶ÔÏó£¬Ôò¶¼µ÷ÓÃ×ÓÀàµÄº¯Êý¡£
Ïà¹ØÎĵµ£º
ÔÚANSI±ê×¼»¯ºó£¬CÓïÑԵıê×¼ÔÚÒ»¶ÎÏ൱µÄʱ¼äÄÚ¶¼±£³Ö²»±ä£¬¾¡¹ÜC++¼ÌÐøÔڸĽø¡££¨Êµ¼ÊÉÏ£¬Normative Amendment1ÔÚ1995ÄêÒѾ¿ª·¢ÁËÒ»¸öеÄCÓïÑÔ°æ±¾¡£µ«ÊÇÕâ¸ö°æ±¾ºÜÉÙΪÈËËùÖª¡££©±ê×¼ÔÚ90Äê´ú²Å¾ÀúÁ˸Ľø£¬Õâ¾ÍÊÇISO9899:1999£¨1999Äê³ö°æ£©¡£Õâ¸ö°æ±¾¾ÍÊÇͨ³£Ìá¼°µÄC99¡£Ëü±»ANSIÓÚ2000ÄêÈýÔ²ÉÓá£
¡¡¡¡ÔÚC99ÖаüÀ ......
±àÒëÆ÷£ºvc++6.0(ÒòΪ´ËÖÖʵÏÖÒÀÀµ±àÒëÆ÷´¦Àí)
´Ë´¦Ö»¼òÒªÐðÊöһϻúÖÆ¡£²¢¸½²¿·Ö¹Ø¼üÖ¸ÁîÐòÁС£
×¼±¸£º
1£¬¹ØÓÚEBP£º³Æ×öÕ»»ùÖ·Ö¸Õ롣ΪʲôÕâÑù˵ÄØ£¿ÎÒÃÇÏÈÀ´¿´¿´º¯Êýµ÷ÓõĹý³Ì£º
²ÎÊý´ÓÓÒµ½×óѹջ¡£
callÖ¸ÁîÖ´ÐУ¬¸ÃÖ¸Áµ¼ÖÂEIPѹջ¡£
ÿ¸öº¯ÊýÇ°Á½¾ä±Ø¶¨ÊÇ£ºpush ebp mov ebp,esp¡£Ôòca ......
ÔÚÏîÄ¿ÊôÐÔÒ³ --> ÅäÖÃÊôÐÔ --> C/C++ --> Êä³öÎļþÀïÃ棬½«»ã±àÊä³öµÄÏÂÀÁбí´ÓÎÞÁбíÑ¡ÔñΪÄãÐèÒª»ã±àÊä³öµÄÄÚÈÝ£¬±ÈÈ瓽öÁгö³ÌÐò¼¯(/FA)”£¬Èçͼ1-1£¬Í¼1-2£º
ͼ1-1
ͼ1-2
------------------------------------------------------------------------------------------------ ......
#include "stdio.h"
#include "malloc.h"
typedef int elemtype;
struct node
{
elemtype data;
struct node *next;
};
typedef struct node NODE;
NODE * creat(NODE *head)
{
NODE *p,*q;
elemtype i;
head=(NODE*)malloc(sizeof(NODE));
scanf("%d",&(head->data));
p=head;
......
ÔÚÌÖÂÛÈ«¾Ö±äÁ¿Ö®Ç°ÎÒÃÇÏÈÒªÃ÷°×¼¸¸ö»ù±¾µÄ¸ÅÄ
1. ±àÒëµ¥Ôª(Ä£¿é)£º
ÔÚIDE¿ª·¢¹¤¾ß´óÐÐÆäµÀµÄ½ñÌ죬¶ÔÓÚ±àÒëµÄһЩ¸ÅÄîºÜ¶àÈËÒѾ²»ÔÙÇå³þÁË£¬ºÜ¶à³ÌÐòÔ±×îŵľÍÊÇ´¦ÀíÁ¬½Ó´íÎó(LINK ERROR), ÒòΪËü²»Ïñ±àÒë´íÎóÄÇÑù¿ÉÒÔ¸ø³öÄã³ÌÐò´íÎóµÄ¾ßÌåλÖã¬Äã³£³£¶ÔÕâÖÖ´íÎó¸Ðµ½°ÃÄÕ£¬µ«ÊÇÈç¹ûÄã¾ ......