ÈçºÎʹÓ÷ºÐÍÄ£擬virtual? (C/C++) (template)
ÍøÉÏÒ»µÀ½ðɽµÄÃæÊÔÌ⣺
http://topic.csdn.net/u/20100524/14/0eff992a-2849-4db6-bdaa-d4a200e79b7c.html
Çë·Ö±ðÓÃC++µÄÃæÏò¶ÔÏóºÍ·ºÐÍ»úÖÆ£¬±àдʵÏÖTemplate MethodģʽµÄʾÀý´úÂ룬²¢±È½ÏÁ½ÖÖ·½Ê½¸÷×ÔµÄÓÅȱµã¡£
ÓÃÐ麯ÊýʵÏÖTemplate MethodµÄ·½Ê½¾Í²»¶à˵ÁË¡£Ó÷ºÐ͵ķ½Ê½ÊµÏÖ¶à̬ÔÚATLÀïÃæÓдóÁ¿µÄÓõ½£¡
·ºÐ͵ÄÓÅÊƾÍÔÚÓÚÆäÖ´ÐÐЧÂʸߣ¡±àÒëÆÚ¶à̬£¡ÕâÒ²ÊÇATL/WTLÓÅÓÚMFCµÄµØ·½£¡
ÖÁÓÚ·ºÐÍʵÏÖ¶à̬µÄÁÓÊÆ£¬ÎÒÍüÁË£¬µ«Ó¦¸ÃÊÇ·ºÐÍûÓÐÐ麯Êý¹¦ÄÜÇ¿´ó£¬ºÃÏñÔڶ༶¼Ì³ÐϾÍʧЧÁË°É£¿±ÈÈçÖ»ÄÜÓÃÓÚBASE-DeriveÁ½¼¶¼Ì³Ð£¬¶ÔÓÚBase-Derive-DeriveDeriveÔò²»ÐУ¡
²»¶à˵ÁË£¬¿´¿´ÈçºÎÓ÷ºÐÍʵÏÖTemplate Methodģʽ°É¡££º£©
ת×Ô£ºhttp://kb.cnblogs.com/a/873808/
Abstract
OO×îÖØÒªµÄ¶àÐÍ/¶à態¾ÍÊÇÓÃ繼³Ð + virtual來Íê³É£¬virtual雖ºÃÓ㬵«¸¶³öµÄ´ú價¾ÍÊÇ¡º¸ü¶àµÄ記憶體¡»+¡º¸üÂýµÄËٶȡ»£¬±¾ÎĽé紹ʹÓ÷ºÐÍ來Ä£擬virtual機ÖÆ¡£
Introduction
Ê×ÏÈ聲Ã÷£¬這並²»ÊÇÎÒ獨創µÄ·½·¨£¬¶øÊÇATLËùʹÓõķ½Ê½£¬請參¿¼(轉貼) ATL²¼á£Ö®ÏµÄÃØÃÜ(3) (C++) (template)
為ʲ麼ÒªÓ÷ºÐÍ來Ä£擬virtual機ÖÆÄØ?
Ö÷ÒªÊÇÒò為virtual機ÖÆÐèÀûÓõ½vtable£¬ËùÒÔ較Õ¼記憶體£¬Óֵÿ¿vptrÔÚrun-time執ÐжàÐÍ£¬ËùÒÔ執ÐÐËÙ¶È較Âý£¬ËùÒÔATL²ÅÏëÀûÓ÷ºÐÍ這種compile-time機ÖÆ讓component盡¿ÉÄܵÄС£¬盡¿ÉÄܵĿ졣
Example Code
/**//*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : template_virtual.cpp
Compiler : Visual C++ 8.0 / BCB 6.0 / gcc 3.4.2 / ISO C++
Description : Demo how to use generics to simulate virtual
Release : 08/28/2007 1.0
*/
#include <iostream>
using namespace std;
template <typename Derived>
class Base {
public:
void func()&nb
Ïà¹ØÎĵµ£º
ÎÄÕÂÀ´×Ô£ºhttp://mayer.vokaa.com/archives/16
¶ÔÓÚÒ»¸öÇ°¶Ë¹¤×÷Õߣ¬¶¼ÖªµÀ·ûºÏW3C¹æ·¶¶ÔÓÚÍøÒ³µÄ¿çä¯ÀÀÆ÷¹¤×÷´øÀ´ºÃ´¦£¬²¢ÄÜʹÍøÒ³ÔÚ²»Í¬µÄä¯ÀÀÆ÷Ö®¼ä»¥Ïà¼æÈÝ¡£
ÔÚÕâÀïÎÒÃÇÒ»Ò»Áоٻ¥ÁªÍøÉÏËùÌṩµÄ½â¾ö°ì·¨¼°Ò»Ð©ÎÒ¸öÈ˵Ľ¨Ò鼰ʵ¼ù°¸Àý¡£
Æäʵ£¬ÏÖÔÚ¶àÊýÈ˶¼»áʹÓÃHackµÄ·½·¨½â¾ö£¬µ«Èç¹ûDIVºÍCSSµÄ½á¹¹ÇåÎú¡¢ºÏÀí£ ......
·ÇʱÉСñ2010ÐÂ¿î ¹¬Í¢¸´¹ÅÂÞÂíЬÕæƤÁ¹Ð¬ÊæÊÊƽµ×ЬŮЬ
189.0Ôª
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö
1¡¢Õ»Çø£¨stack£©— ³ÌÐòÔËÐÐʱÓɱàÒëÆ÷×Ô¶¯·ÖÅ䣬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£³ÌÐò½áÊøʱÓɱàÒëÆ÷×Ô¶¯ÊÍ·Å¡£
2¡¢¶ÑÇø£¨h ......
typedef struct
{
BYTE baOrigMDN[8]; /* Ö÷½ÐÓû§MDN */
BYTE baDestMDN[8]; /* ±»½ÐÓû§MDN */
BYTE bOrigIsVIP;   ......
pid_t pid=fork()
it has 3 situation for the return result pid
0 child
>0 parent process
<0 fork fail
fork create a new process and it parent live alse when the child process had been created ......