Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,313 of 33,346    |
|    red floyd to kira kira    |
|    Re: message processing using template    |
|    18 May 12 14:30:45    |
   
   c1cc3b50   
   From: no.spam.here@its.invalid   
      
   On 5/18/2012 6:00 AM, kira kira wrote:   
   > Hi,   
   >   
   > Suppose there are messages required to process. the code would look   
   > like this.   
   > void process (int type)   
   > {   
   > if (type == MSG_TYPE_A)   
   > {   
   > processMsgA();   
   > }   
   > else if (type == MSG_TYPE_B)   
   > {   
   > processMsgB();   
   > }   
   > }   
   >   
   > I would like to know if it is possible to use template to achieve the   
   > same result.   
   >   
      
   Use inheritance an virtual functions.   
      
   struct Message {   
    virtual void Process() = 0;   
    virtual ~Message() { }   
   };   
      
   struct MsgA : public Message {   
    void Process() {   
    // process MsgA   
    }   
   };   
      
   struct MsgB : public Message {   
    void Process() {   
    // process MsgB   
    }   
   };   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca