Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct A
- {
- A() { std::cout << "ctor " << this << std::endl; }
- ~A() { std::cout << "dtor " << this << std::endl; }
- void f() { std::cout << "f " << this << std::endl; }
- };
- struct S
- {
- inline static A a; // C++17 inline variable, thus also a definition
- };
- #include "header.h"
- int main()
- {
- S::a.f();
- }
- #include "header.h"
- #include "header.h"
- #include "header.h"
- ctor 010D4020
- ctor 010D4020
- ctor 010D4020
- ctor 010D4020
- f 010D4020
- dtor 010D4020
- dtor 010D4020
- dtor 010D4020
- dtor 010D4020
- ctor 010D4020
- f 010D4020
- dtor 010D4020
- struct A
- {
- A() { std::cout << "ctor "; }
- ~A() { std::cout << "dtor "; }
- };
- A a; // in one of the TU's
- extern A a; // in all other TU's
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement