Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ typedef enum: Invalid conversion from int to enum

Tags:

c++

enums

typedef

typedef enum{
 Adjust_mode_None = 0,
 Adjust_mode_H_min,
 Adjust_mode_H_max,
 Adjust_mode_S_min,
 Adjust_mode_S_max,
 Adjust_mode_V_min,
 Adjust_mode_V_max
}Adjust_mode;

and at some point I want to do:

adjust_mode_ = (adjust_mode_+1)%7; 

but I get

Invalid conversion from int to Adjust_mode

This is ok in other languages, what is wrong in C++? Do I need to define some operator?

like image 491
nacho4d Avatar asked Apr 13 '26 06:04

nacho4d


1 Answers

use static_cast. You need an explicit conversion.

adjust_mode_ = static_cast<Adjust_mode>(adjust_mode_+1)%7;
like image 50
aJ. Avatar answered Apr 15 '26 21:04

aJ.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!