Difference between Enum and Define Statements

后端 未结 18 2565
终归单人心
终归单人心 2020-11-30 00:27

What\'s the difference between using a define statement and an enum statement in C/C++ (and is there any difference when using them with either C or C++)?

For exampl

18条回答
  •  悲哀的现实
    2020-11-30 00:58

    Besides all the thing already written, one said but not shown and is instead interesting. E.g.

    enum action { DO_JUMP, DO_TURNL, DO_TURNR, DO_STOP };
    //...
    void do_action( enum action anAction, info_t x );
    

    Considering action as a type makes thing clearer. Using define, you would have written

    void do_action(int anAction, info_t x);
    

提交回复
热议问题