¡¾C/C++¡¿C++ÐéÎö¹¹º¯ÊýµÄ×÷ÓÃ
1¡¢×÷ÓÃ
ΪÁËÔÚʵÏÖ¶à̬µÄʱºò²»Ôì³ÉÄÚ´æÐ¹Â¶,
Èç¹û»ùÀàÎö¹¹º¯Êýǰ²»¼Óvitual£¬ÅÉÉúÀà¶ÔÏó±»Ïú»Ùºó£¬Ö»»áµ÷ÓûùÀàµÄÎö¹¹º¯Êý£¬¶ø²»»áÈ¥µ÷ÓÃÅÉÉúÀàµÄÎö¹¹º¯Êý¡£
2¡¢¶ÔÓÚÕý³£µÄº¯Êý£¬Èç¹û»ùÀàÖÐÉùÃ÷Ϊvirtual£¬ÔòÅÉÉúÀà¿ÉÒÔ²»ÓÃÔÙдvirtual
// CPPTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class Base
{
public:
Base(){}
virtual ~Base()
{
printf("Base Destructor!\n");
}
virtual void Func()
{
printf("Base Func!\n");
}
private:
int m_iData;
};
class Derived : public Base
{
public:
Derived(){}
~Derived()
{
printf("Derived Destructor!\n");
}
void Func()
{
printf("Derived Func!\n");
}
};
class Derived2 : public Derived
{
public:
Derived2(){}
~Derived2()
{
printf("Derived2 Destructor!\n");
}
void Func()
{
printf("Derived2 Func!\n");
}
};
int main(int argc, char* argv[])
{
Base *pb = new Base;
pb->Func();
Base *pd = new Derived;
pd->Func();
Base *pd2 = new Derived2;
pd2->Func();
delete pb;
delete pd;
delete pd2;
return 0;
}
½á¹û£º
Base Func!
Derived Func!
Derived2 Func!
Base Destructor!
Derived Destructor!
Base Destructor!
Derived2 Destructor!
Derived Destructor!
Base Destructor!
Ïà¹ØÎĵµ£º
żȻÀ´ÕÒÒ»¸öÎļþ£¬È´·¢ÏÖÕâÀï¹ØÓÚvc++ºÍDelphiµÄÌÖÂÛºÜÊǼ¤ÁÒ¡£¿´ÁË´ó¼ÒдµÄһЩ
ÎÄÕ£¬¾õµÃÓÐЩ¿´·¨ÕýÈ·£¬ÓÐЩ¾ÍºÜÆ«ÆÄÉõÖÁ´íÎó(Ò²ÐíÎÞÖª£¿ºÜ±§Ç¸ÎÒÕâÑù˵:-)¡£ÎÒ
ÎÞÒâÓëÈκÎÈËÕùÂÛ£¬¸üÔ¸Òâ°ÑÕâ¿´³ÉÊǼ¼ÊõÉϵÄÌÖÂÛ¡£Ó¦¸Ã±¾×Ź«Õý£¬²»´øÆ«¼ûµÄ̬¶È
(Õâ²¢²»Òâζ×Å·ÇҪƽ·ÖÇïÉ«£¬Ò»ÇÐÓ¦ÒÔÊÂʵΪ׼)¡£ÎÒÓùý³ýtp1ÒÔÍâµÄËùÓ ......
@echo --------------------- ÓÃÓÚ¡¶Ò»¸ö²Ù×÷ϵͳµÄʵÏÖ¡·µÄ cmd ---------------------
@echo off
mode con cols=80 lines=60 ::ǰһ¸öÊý×Ö»ò×ÖĸΪ±³¾°É«£¬ºóÒ»¸öÊý×Ö»òÕß×ÖĸΪǰ¾°É«£¬ÏÂÃæÊÇһЩÑÕÉ«¶ÔÓ¦µÄÊý×Ö»ò×Öĸ£º
::0£½ºÚ¡¢1£½À¶¡¢2£½ÂÌ¡¢3£½Ç³ÂÌ¡¢4£½ºì¡¢5£½×Ï¡¢6£½»Æ¡¢7=°×¡¢8=»Ò¡¢9=µÀ¶¡¢A£½µ ......
1¡¢int 4×Ö½Ú
long 8×Ö½Ú
float 4×Ö½Ú
double 8×Ö½Ú
long double 16×Ö½Ú
2¡¢Ò»¸ö×Ö·û±äÁ¿Ö»ÄÜ´æ·ÅÒ»¸ö×Ö·û¡¢Ò»¸ö×Ö½Ú´æ·ÅÒ»¸ö×Ö½Ú
char c;
c = 'a'; c = '\034' ......
ÌâÄ¿ÈçÏ£º
ÒªÇóÏÔʾ³öµ¥ÔµÄÈÕÀú£¬Óû§ËµÃ÷Õâ¸öÔµÄÌìÊýºÍ±¾ÔÂµÄÆðʼÈÕÊÇÐÇÆÚ¼¸£¬¼´¿ÉÊä³ö¸ÃÔµÄÈÕÀú¡£
¾ÍÊÇÕâôһµÀ¼òµ¥µÄ³ÌÐò£¬ÎÒ±ïÁËÁ½Ìì×ÜËãŪ³öÀ´ÁË£¬½á¹ûËäÈ»´ïµ½ÁËÒªÇ󣬵«¾àÀëÎÒÔ¤ÏëµÄ»¹ÓÐÒ»¶Î²î¾à£¬ÏȰѳÌÐò
´úÂë·ÅÔÚÉÏÃæ£¬Ï£Íû´ó¼Ò¶àÌáÐÞ¸ÄÒâ¼û¡£
/******************************************************* ......