- Mastering C++ Programming
- Jeganathan Swaminathan
- 113字
- 2021-07-02 18:28:47
Inline variables
Just like the inline function in C++, you could now use inline variable definitions. This comes in handy to initialize static variables, as shown in the following sample code:
#include <iostream>
using namespace std;
class MyClass {
private:
static inline int count = 0;
public:
MyClass() {
++count;
}
public:
void printCount( ) {
cout << "\nCount value is " << count << endl;
}
};
int main ( ) {
MyClass obj;
obj.printCount( ) ;
return 0;
}
The preceding code can be compiled and the output can be viewed with the following commands:
g++-7 main.cpp -std=c++17
./a.out
The output of the preceding code is as follows:
Count value is 1
推薦閱讀
- Visual C++程序設計學習筆記
- Kinect for Windows SDK Programming Guide
- 軟件測試技術指南
- C++新經典
- Python深度學習:基于TensorFlow
- 深入淺出React和Redux
- AIRIOT物聯網平臺開發框架應用與實戰
- Android群英傳
- SQL Server 2008 R2數據庫技術及應用(第3版)
- Kubernetes進階實戰
- Oracle數據庫編程經典300例
- Python計算機視覺和自然語言處理
- Ext JS 4 Plugin and Extension Development
- Java多線程并發體系實戰(微課視頻版)
- Oracle Database 12c DBA官方手冊(第8版)