static_cast<int&>((eTimeSource))); //This doesn't work.
Right, it doesn't work, because eTimeSource
is not an int
so you can't bind a int&
to it.
(int&)((eTimeSource))); //This does work.
Wrong, that doesn't work either, it just appears to. The C-style cast lies to the compiler and says "just make it this type, even if that's not legal". Just because something compiles doesn't mean it works.
why is it that when eTimeSource
was an int
no casting is required at all to pass the integer by reference?
Because you can bind an int&
to an int
but not to a different type, and eTimeSource
is a different type. An int&
is a reference to an int
. If you could bind it to a different type it wouldn't refer to an int
, would it?
If the code reviewer said to change the variable to an enumeration type they probably also meant for you to change the function parameter to take a ControlSource&