В частности, у меня есть такой пример:
(На godbolt)
Код: Выделить всё
// a.h
void initA();
void setA(int val);
int getA();
Код: Выделить всё
// a.cpp
#include "a.h"
static int a;
void initA() {
a = 1;
}
void setA(int val) {
a = val;
}
int getA() {
return a;
}
Код: Выделить всё
// b.h
class B {
public:
B();
};
Код: Выделить всё
// b.cpp
#include "b.h"
#include "a.h"
B::B() {
setA(12);
}
Код: Выделить всё
// main.cpp
#include "a.h"
#include "b.h"
#include
void local_statics();
int main() {
initA(); // sets a static namespace-scope int `a` to 1
local_statics();
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/77759430/c-when-exactly-are-function-scope-statics-initialized[/url]
Мобильная версия