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

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
主站蜘蛛池模板: 翁源县| 呼玛县| 嘉鱼县| 五华县| 宝丰县| 镇原县| 邵武市| 和政县| 尚志市| 六枝特区| 扬中市| 合作市| 兴义市| 扶余县| 日照市| 通山县| 平乐县| 红河县| 海南省| 永宁县| 东乡族自治县| 泌阳县| 望江县| 吉林市| 呼伦贝尔市| 潜山县| 体育| 光山县| 禹城市| 临安市| 镇原县| 海阳市| 富锦市| 沙湾县| 张家界市| 金沙县| 翁源县| 大石桥市| 白银市| 三亚市| 尚义县|