官术网_书友最值得收藏!

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
主站蜘蛛池模板: 红桥区| 溧阳市| 扶绥县| 锡林郭勒盟| 龙里县| 时尚| 富锦市| 长沙市| 泾源县| 平山县| 山东| 都兰县| 石景山区| 同德县| 镇雄县| 砚山县| 会理县| 陕西省| 左云县| 临邑县| 遂平县| 勃利县| 嘉义市| 绥宁县| 尚义县| 那坡县| 微博| 安庆市| 库尔勒市| 金乡县| 南投市| 太仓市| 桂东县| 谢通门县| 麟游县| 安国市| 双峰县| 封开县| 青海省| 连江县| 绍兴市|