creating Pointer to class inside its member function to achieve polymorphism -


have @ below piece of code.

//base cls declaration:  class cmdparser_c {     public:      cmdparser_c(){}       virtual ~cmdparser_c(){}       boolean parseinputcmd(uint8*);     virtual boolean processinputcmd(uint8* );     virtual boolean processinputcmdargs(uint8* cmdlist_ptr, uint8 noofargs); }   //one of member function definition:  boolean cmdparser_c::parseinputcmd(uint8* cmdbuff_ptr) {     cmdparser_c *tstobj[max_parsers]; // <-- creating array of base cls ptr      rtccmdparser_c    rtctstobj;     uiparser_c        uip;      tstobj[0] = &rtctstobj;          // <-- assigning child1 cls obj     tstobj[1] = &uip;                // <-- assigning child2 cls obj       if (tstobj[0]->processinputcmd(&inputcmd_ptr[0][0]))     {         //     }      else if (tstobj[1]->processinputcmd(&inputcmd_ptr[0][0]))     {         //     }  } 

the code working. no issues that. question there flaw in creating array of ptr class inside own member function achieve runtime polymorphism? wrong logic?

i see 1 problem: added specific functionality (parseinputcmd) base class not used in derived classes.

create derived class compositeparser_c : public cmdparser_c { ... } , call other concrete parsers in compositeparser_c::processinputcmd() method.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -