Hi I wrote a casting function from myClass to int and vise versa therefore I made one of the functions as explicit. When doing so I got an error.
The functions:
CircularInt(int n): CircularInt(1, 12 , n) { }
explicit operator int() const{ return current;};
Error on:
CircularInt hour {1, 10 , 7 }; // current = 7
int i = hour;
Error:
error: cannot convert ‘CircularInt’ to ‘int’ in initialization int i = hour;
When erasing the "explicit" all is good, Why is this?
p.s.
May I mention that I was unable to find a question exactly like this, I found many questions of people that forgot to do explicit, asking what is explicit (didn't find something in those exact question them for me) etc.
Probably this is from not understanding completely understanding explicit...