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
¼´Èç¹ûÓÃ×ÓÀàÖ¸ÕëÖ¸Ïò×ÓÀà¶ÔÏó£¬Ôò¶¼µ÷ÓÃ×ÓÀàµÄº¯Êý¡£
Ïà¹ØÎĵµ£º
±¾ÎÄ°üÀ¨´ó²¿·ÖC±ê×¼¿âº¯Êý£¬µ«Ã»ÓÐÁгöһЩÓÃ;ÓÐÏ޵ĺ¯ÊýÒÔ¼°Ä³Ð©¿ÉÒÔ¼òµ¥µÄ´ÓÆäËûº¯ÊýºÏ³ÉµÄº¯Êý£¬Ò²Ã»Óаüº¬¶à×ֽںͱ¾µØ»¯º¯Êý¡£
±ê×¼¿âÖеĸ÷¸öº¯Êý¡¢ÀàÐÍÒÔ¼°ºê·Ö±ðÔÚÒÔϱê׼ͷÎļþÖÐ˵Ã÷£º
<assert.h> <float.h> <math.h> <stdarg.h> <stdlib.h>
<ctype.h> <limits.h& ......
ÔÚANSI±ê×¼»¯ºó£¬CÓïÑԵıê×¼ÔÚÒ»¶ÎÏ൱µÄʱ¼äÄÚ¶¼±£³Ö²»±ä£¬¾¡¹ÜC++¼ÌÐøÔڸĽø¡££¨Êµ¼ÊÉÏ£¬Normative Amendment1ÔÚ1995ÄêÒѾ¿ª·¢ÁËÒ»¸öеÄCÓïÑÔ°æ±¾¡£µ«ÊÇÕâ¸ö°æ±¾ºÜÉÙΪÈËËùÖª¡££©±ê×¼ÔÚ90Äê´ú²Å¾ÀúÁ˸Ľø£¬Õâ¾ÍÊÇISO9899:1999£¨1999Äê³ö°æ£©¡£Õâ¸ö°æ±¾¾ÍÊÇͨ³£Ìá¼°µÄC99¡£Ëü±»ANSIÓÚ2000ÄêÈýÔ²ÉÓá£
¡¡¡¡ÔÚC99ÖаüÀ ......
²»Öª²»¾õÒѾ¹¤×÷Á½ÄêÁË£¬´ÇÈ¥ÁËÔÀ´µÄ¹¤×÷£¬ÓÖÅÜ»ØÁËÎÒÉÏѧµÄµØ·½¡£½ñÌìÅÜÈ¥Ò»¼ÒÊÒÓѽéÉܵĹ«Ë¾ÃæÊÔ¡£ÎʵÃÎÊÌâͦ¼òµ¥£¬µ«ÎÒ´ðµÄÈ´Õæ²»ÔõôµØ°¡¡£»ØÀ´ÓÖÑо¿ÁËһϣ¬·¢ÏÖÕâЩÎÊÌâÎÒÓ¦¸Ã¶¼Àí½â°¡£¬Ôõôµ½±ðÈËÎÊÆðµÄʱºò¾ÍÈ«ÍüÁËÒ»°ãÄØ¡£ÏëÏëÁË·¢ÏÖ»¹ÊÇѧµÄ²»µ½Î»¡£²»½ûÓÖÏëÆðÁËÕâô¶àÄêÀ´£¬ÎÒ¶¼Ñ§µ½ÁËʲô¶«Î÷ÄØ¡£
& ......
CºÍC++±à³ÌºÍѧϰÎĵµ
1 :Ö¸Õë±äÁ¿Ãû³ÆÒÔpΪÊ××Ö·û£¬ÕâÊdzÌÐòԱͨ³£ÔÚ¶¨ÒåÖ¸ÕëʱµÄÒ»¸öÏ°¹ß
2 :har * p; (int *)p °ÑpÇ¿ÖÆת»»ÎªintÐÍ   ......
×î½üÔÚÍøÉϲéÁ˺öà¹ØÓÚC²¥·ÅwavÕâ·½ÃæµÄ×ÊÁÏ£¬µ÷ÊÔ°ëÌìҲûÓнá¹û£¬Ëѵ½Ò»¸ö±àÒëºÃµÄEXEÎļþÄܲ¥·Å£¬Ã»ÓÐÔ´´úÂ룬·´»ã±à²»ÁË£¬ËÄÜÖ¸µãһϡ£¡£¡£¡£¡£ÒÔÏÂÁ½ÖÖ´úÂë¶Î£º
#include <stdio.h>
#include <dos.h>
/* wavÎļþ½á¹¹ */
typedef struct WaveData
{
unsigned long sample_le ......