I want to return by reference to a variable that's inside a switch, like for example:
sometype & getbar();
void foo() {
switch ( {statement} ) {
case {statement}:
sometype & handle = getbar();
...
But I'm getting compiler errors:
initialization of 'identifier' is skipped by 'case' label
initialization of 'identifier' is skipped by 'default' label
And it looks like it's not possible to do this:
void foo() {
sometype & handle;
switch ( {statement} ) {
case {statement}:
handle = getbar();
...
Because a reference variable requires initialization.
Is there a way to do this with keeping the switch statement?