Coding Standards / Coding Best practices in C++

前端 未结 17 1632
醉话见心
醉话见心 2021-01-02 09:06

Consider the two code segments below. Which one is better and Why? If you have any other idea, please do mention. Where can I find answers to coding p

17条回答
  •  伪装坚强ぢ
    2021-01-02 09:11

    A switch would be a better solution to your problem I think. You would need to overload the method to take in an int param and I don't know if that's something you would want to do or not.

    Bool MyApplication::ReportGenerator::GenerateReport(int i)
    {
      switch(i)
      {
        case 1:
           // do something
           break;
        case 2:
           // do something
           break;
       // etc
     }
     return GeneratReport()
    }
    

    Not really sure what your plan is since you're calling the method recursively and as some point you will want to leave the method.

提交回复
热议问题