1)std :: call_once
A a;
std::once_flag once;
void f ( ) {
call_once ( once, [ ] { a = A {....}; } );
}
Run Code Online (Sandbox Code Playgroud)
2)功能级静态
A a;
void f ( ) {
static bool b = ( [ ] { a = A {....}; } ( ), true );
}
Run Code Online (Sandbox Code Playgroud)