Loosely speaking, a scope is a region in which names can be declared. Names declared in a scope are accessible within that scope and, in some circumstances, also from outside.
(To be pedantically accurate, that is actually a declaration region, and the scope of a name is the part of the program in which the name is valid. It begins where it's declared, and includes the rest of that region and, sometimes, some other regions.)
Scopes are introduced by namespaces, classes, and compound statements (that is, blocks of code statements surrounded by {}
). The last one includes the bodies of functions.
Most objects and functions have names, and each of these names is inside a scope.
So the "scope of a function" could mean two things: either the scope defined by the function's body, in which its local variables are declared; or the scope (either a class or a namespace) in which the function name is declared.
UPDATE: you say you mean the scope of the function name. This always begins immediately after the declaration; where it ends depends on where that declaration was.
- If it is declared inside a namespace, it lasts until that namespace is closed. If the namespace is reopened later in the same translation unit, then it comes back into scope there.
- If it is declared inside a class definition as a member function, then the scope lasts until the end of the class definition. It is also in scope inside the definitions of any derived classes, and also inside the definitions of member of that class or derived classes.
- If it is declared inside a class definition as a friend, or inside a function definition, then the name is actually declared in the surrounding namespace, and the scope is the same as that case.