I encountered this statement(source):
means putting the function calls and scopes in a stack
But how/why would you store scopes?
I encountered this statement(source):
means putting the function calls and scopes in a stack
But how/why would you store scopes?
That statement could be better phrased. You need to make some observations first.
A scope is a semantics construct. It defines where you can use a name (for a variable, type, function, etc.). And what that name will refer to.
There are different types of scopes. Quite a few are only a compile time thing. For instance, namespaces and classes define a scope too.
Functions also define scope, but functions "run". As such, their context must have some sort of run-time representation.
Recursion entails calling the same function, but the functions context must be different for each re-entrant call.
The last point is why "call stacks" are often used to implement function calls. Each stack record relates to the context of the function being run. The names in the functions scope will therefore be referring to items on the call stack.
The answer isn't C++ specific. C++ uses a model of compilation prior to running (at least conceptually, implementations may differ). In the C++ model, scopes are resolved at compile time. The compiler may very well use some sort of stack data structure for this.
At runtime, there's a function call stack, and this often holds both function return addresses and the local variables of each active function, but in C++ this runtime stack doesn't need to hold scopes.