کلمه static داخل مثالی که زدین بر می گرده به تعریف متغیر range
متغیری که static باشه :
1_ فقط داخل Scope ای که تعریف شده قابل استفادست
2_ تا پایان برنامه حافظش پایداره
یعنی اگر این struct با static گلوبال باشه فقط داخل همین فایل قابل استفاده هست ا
اگر داخل تابع تعریف شده باشه فقط داخل تابع قابل استفاده هست.
یا اگر این struct رو داخل یک کلاس تعریف می کردین میشد static member و برای استفاده نیاز به ساخت شی از کلاس نداشتین.
استاندارد c++ بخش 3.5 ( N 3690 ) در مورد زمانی که متغیر بصورت global تعریف شده باشه
A name is said to have linkage when it might denote the same object, reference, function, type, template,
namespace or value as a name introduced by a declaration in another scope:
— When a name has external linkage , the entity it denotes can be referred to by names from scopes of
other translation units or from other scopes of the same translation unit.
— When a name has internal linkage , the entity it denotes can be referred to by names from other scopes
in the same translation unit.
— When a name has no linkage , the entity it denotes cannot be referred to by names from other scopes.
و
3 A name having namespace scope (3.3.6) has internal linkage if it is the name of
— a variable, function or function template that is explicitly declared static; or,
— a non-volatile variable that is explicitly declared const or constexpr and neither explicitly declared
extern nor previously declared to have external linkage; or
— a data member of an anonymous union.
و
An unnamed namespace or a namespace declared directly or indirectly within an unnamed namespace has
internal linkage. All other namespaces have external linkage. A name having namespace scope that has not
been given internal linkage above has the same linkage as the enclosing namespace if it is the name of
— a variable; or
— a function; or
— a named class (Clause 9), or an unnamed class defined in a typedef declaration in which the class has
the typedef name for linkage purposes (7.1.3); or
— a named enumeration (7.2), or an unnamed enumeration defined in a typedef declaration in which the
enumeration has the typedef name for linkage purposes (7.1.3); or
— an enumerator belonging to an enumeration with linkage; or
— a template.