I am going through a c++ code base and in the header file (Executor.h) there is the public field definition
typedef std::pair<ExecutionState*,ExecutionState*> StatePair;
Inside the cpp file (Executor.cpp) there is a line
Executor::StatePair
Executor::fork(ExecutionState ¤t, ref<Expr> condition, bool isInternal) { /* function definition */ }
in which this field is referenced right before one of the member function definitions
What is the purpose of stating the field name right before the definition ? Is it scoping issues ?
Thanks
The
StatePairis a type. Its purpose in front of the function definition is to state the return type of the functionNote the
typedefin the definition ofStatePair. It introduces a name alias for a type. In this casestd::pair<ExecutionState*,ExecutionState*>will also be calledStatePair, so you don’t have to write that long type nameThe return type of a function names the type that the value returned from the function must belong to. E.g. in the case of
the function
fmust return an integer (int), so we could write a definition like this:there could be other statements in the function body, but the last one has to be a
returnwith an integer value after it (in the bavode example the value is0)As C++ does not care about new lines (treats them as regular white-space), the format
is the same as for the above function.