Added example of static inline member variables to #inline varibles (#77)

* Added example of static inline member variables to #inline varibles
This commit is contained in:
Frede
2020-01-26 20:00:18 +01:00
committed by Anthony Calandra
parent 1c53669d1f
commit 31cc7ac850
2 changed files with 23 additions and 3 deletions

View File

@@ -150,6 +150,16 @@ S x2 = S{123}; // mov eax, dword ptr [.L_ZZ4mainE2x2]
// .L_ZZ4mainE2x2: .long 123 // .L_ZZ4mainE2x2: .long 123
``` ```
It can also be used to declare and define a static member variable, such that it does not need to be initialized in the source file.
```c++
struct S {
S() : id(count++) {}
~S() {count--;}
int id;
static inline int count{0}; // declare and initialize count to 0 within the class
};
```
### Nested namespaces ### Nested namespaces
Using the namespace resolution operator to create nested namespace definitions. Using the namespace resolution operator to create nested namespace definitions.
```c++ ```c++

View File

@@ -435,6 +435,16 @@ S x2 = S{123}; // mov eax, dword ptr [.L_ZZ4mainE2x2]
// .L_ZZ4mainE2x2: .long 123 // .L_ZZ4mainE2x2: .long 123
``` ```
It can also be used to declare and define a static member variable, such that it does not need to be initialized in the source file.
```c++
struct S {
S() : id(count++) {}
~S() {count--;}
int id;
static inline int count{0}; // declare and initialize count to 0 within the class
};
```
### Nested namespaces ### Nested namespaces
Using the namespace resolution operator to create nested namespace definitions. Using the namespace resolution operator to create nested namespace definitions.
```c++ ```c++