I'm asking about the definition of enum type

Asked 2 years ago, Updated 2 years ago, 140 views

enum {RANDOM, IMMEDIATE, SEARCH} strategy;
strategy = IMMEDIATE;

You can use it like this on C++, but there's an error on C It's too hard.What should I do?

error: conflicting types for ‘strategy’
error: previous declaration of ‘strategy’ was here

c enum

2022-09-22 22:19

1 Answers

You can use it like that on C++, In C, you have to write it like this.

typedef enum {RANDOM, IMMEDIATE, SEARCH} strategy;
strategy my_strategy = IMMEDIATE;

And personally, it is easier to manage the type and variable, so I would recommend using it as below

typedef enum {RANDOM, IMMEDIATE, SEARCH} strategy_type;
strategy_type my_strategy = IMMEDIATE;


2022-09-22 22:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.