c++ - How to call a part of a function not the whole function in somewhere? -


i trying call condition defined inside of function in somewhere else don't know if possible. function member of class:

  void cmaindlg::ontcnselchangetab1(nmhdr *pnmhdr, lresult *presult) {     int ii=m_tabctrl1.getcursel();    if(ii==0)         {          getdlgitem....          getdlgitem....         } else if(ii==1)    {     ///getdlgitem....    ///getdlgitem....    } else   {   ////   }   }     // todo: add control notification handler code here     *presult = 0; } 

i trying call , execute following loop directly somewhere else don't know how.

if(ii==0)     { getdlgitem.... getdlgitem.... } 

if want call piece of code somewhere else, need make function. can call new function twice: original code location, , want use again:

void your_function() {     // 'loop'     // note 'if' not loop condition     if(ii==0)     {         getdlgitem....         getdlgitem....     } }  void cmaindlg::ontcnselchangetab1(nmhdr *pnmhdr, lresult *presult) {     ...     your_function();     ... }  // somewhere else, call again: void something_else() {     ...     your_function();     ... } 

Comments