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

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
主站蜘蛛池模板: 射阳县| 建宁县| 安多县| 肇庆市| 衡阳县| 阿鲁科尔沁旗| 万州区| 武宣县| 铜山县| 阳城县| 临沂市| 扎赉特旗| 赣州市| 林口县| 仲巴县| 宝应县| 商城县| 华池县| 彰武县| 保康县| 高雄县| 闸北区| 桂平市| 聂拉木县| 海兴县| 谢通门县| 江城| 绩溪县| 琼海市| 攀枝花市| 龙陵县| 仲巴县| 潼关县| 威信县| 都江堰市| 精河县| 延庆县| 贵德县| 玉溪市| 阿坝县| 台北县|