You can only goto
labels in the same function, and it's very poor practice to break a function across source files (which is only possible if an #include
d file contains the first part of the function). To transfer execution, you normally want to use function calls (whether to a hardcoded function or one identified by e.g. a function pointer or std::function<>
) and return
statements, sometimes throw
and exceptions, and very very rarely something unusual like setjmp
/longjmp
(if you need to ask this question you shouldn't be playing with those latter functions). You should explain more about your program - ideally post some code - if you want specific advice on what suits your needs.
Update: now you've posted some code, you could consider something like this...
// source.h
enum Flow { Outer, Continue }; // whatever names make sense to you...
Flow callingfunc();
// main.cc
#include "source.h"
if (callingfunc(...) == Outer) goto outer;
// source.cc
#include "source.h"
Flow callingfunc() { ...; return Outer; ... return Continue; }
It's best to try to find a better name than "Outer"... something that communicates the condition that callingfunc
has found or the consequent processing it's recommending (e.g. Timeout
, Can_Retry
, Model_Unsolvable
).