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
¼´Èç¹ûÓÃ×ÓÀàÖ¸ÕëÖ¸Ïò×ÓÀà¶ÔÏó£¬Ôò¶¼µ÷ÓÃ×ÓÀàµÄº¯Êý¡£
Ïà¹ØÎĵµ£º
ʱ³£ÔÚcppµÄ´úÂëÖ®Öп´µ½ÕâÑùµÄ´úÂë: PnQ
PnQ
#ifdef __cplusplus PnQ
extern "C" { PnQ
#endif PnQ
PnQ
//Ò»¶Î´úÂë PnQ
PnQ
#ifdef __cplusplus PnQ
} PnQ
#endif PnQ
¡¡¡¡ÕâÑùµÄ´úÂëµ½µ×ÊÇʲôÒâË¼ÄØ£¿Ê×ÏÈ£¬__cplusplusÊÇcppÖеÄ×Ô¶¨Òåºê£¬ÄÇô¶¨ÒåÁËÕâ¸öºêµÄ»°±íʾÕâÊÇÒ»¶ÎcppµÄ´úÂ룬Ҳ¾ÍÊÇ˵£¬ÉÏÃæµÄ´úÂëµ ......
ÔÚÏîÄ¿ÊôÐÔÒ³ --> ÅäÖÃÊôÐÔ --> C/C++ --> Êä³öÎļþÀïÃæ£¬½«»ã±àÊä³öµÄÏÂÀÁбí´ÓÎÞÁбíÑ¡ÔñΪÄãÐèÒª»ã±àÊä³öµÄÄÚÈÝ£¬±ÈÈ瓽öÁгö³ÌÐò¼¯(/FA)”£¬Èçͼ1-1£¬Í¼1-2£º
ͼ1-1
ͼ1-2
------------------------------------------------------------------------------------------------ ......
n Óñêʶ·û´ú±íÒ»¸ö³£Á¿£¬³ÆÎª·ûºÅ³£Á¿¡£ n ·ûºÅ³£Á¿Óë±äÁ¿²»Í¬£¬ËüµÄÖµÔÚÆä×÷ÓÃÓòÄÚ²»Äܸı䣬Ҳ²»ÄÜÔÙ±»¸³Öµ¡£ n ʹÓ÷ûºÅ³£Á¿µÄºÃ´¦ÊÇ£º Ø º¬ÒåÇå³þ£» Ø ÄÜ×öµ½¡°Ò»¸ÄÈ«¸Ä¡±¡£ --»°Ëµ£º²»ÖªµÀcÀïÃæÓÐûÓÐÈ«¾Ö±äÁ¿µÄ¶«¶«£¬Óеϰ£¬ÕâÁ½¸öµÄʵ¼ÊÓô¦ÓÐɶ×ÓÇø±ðÄØ£¿¿´¿´ÔÙ˵ Êý¾Ý½á¹¹+Ëã·¨=³ÌÐò ÖÕÓÚÖªµÀÕâ ......
ÕûÐͳ£Á¿¾ÍÊÇÕû³£Êý¡£Ê¹ÓõÄÕû³£ÊýÓа˽øÖÆ¡¢Ê®Áù½øÖƺÍÊ®½øÖÆÈýÖÖ¡£ Ê®½øÖÆÕû³£Êý²»ÄÜÓÐǰµ¼0£¬²»ÄÜÓзÇÊý×Ö×Ö·û¡£ °Ë½øÖÆÕû³£Êý±ØÐëÒÔ0¿ªÍ·£¬²»ÄÜÓзÇÊý×Ö×Ö·û¡£ Ê®Áù½øÖÆÕû³£Êý±ØÐëÒ»0X»ò0x¿ªÍ·£¬²»ÄÜÓзǷ¨×Öĸ£¨ ......
×î½üÔÚÍøÉϲéÁËºÃ¶à¹ØÓÚC²¥·ÅwavÕâ·½ÃæµÄ×ÊÁÏ£¬µ÷ÊÔ°ëÌìҲûÓнá¹û£¬Ëѵ½Ò»¸ö±àÒëºÃµÄEXEÎļþÄܲ¥·Å£¬Ã»ÓÐÔ´´úÂ룬·´»ã±à²»ÁË£¬ËÄÜÖ¸µãһϡ£¡£¡£¡£¡£ÒÔÏÂÁ½ÖÖ´úÂë¶Î£º
#include <stdio.h>
#include <dos.h>
/* wavÎļþ½á¹¹ */
typedef struct WaveData
{
unsigned long sample_le ......