Class lookup structure array in C++

后端 未结 4 1494
花落未央
花落未央 2021-01-16 11:51

I\'m trying to create a structure array which links input strings to classes as follows:

struct {string command; CommandPath cPath;} cPathLookup[] = {
    {\         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 12:36

    I assume you are trying to implement a table lookup as a replacement to a large if\else statement in your system.

    For clarity I would go with a Factory design pattern instead. Having large if/else logic is only really bad if it is repeated around your code in many places. As long as it is in one place i.e. a Factory then in my opinion, you have a good design.

提交回复
热议问题