1 Star 0 Fork 0

gitstr/modern-cpp-tutorial

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
2.21.inline.variable.cpp 702 Bytes
一键复制 编辑 原始数据 按行查看 历史
//
// 2.21.inline.variable.cpp
// chapter 2 language usability
// modern cpp tutorial
//
// created by changkun at changkun.de
// https://github.com/changkun/modern-cpp-tutorial
//
#include <iostream>
struct Widget {
// C++17: define and initialize a static data member inside the class
static inline int count = 0;
Widget() { ++count; }
};
// C++17: an inline variable can be safely defined in a header and
// included by multiple translation units without violating the ODR
inline int global_value = 42;
int main() {
Widget a, b, c;
std::cout << "Widget::count = " << Widget::count << std::endl; // 3
std::cout << "global_value = " << global_value << std::endl; // 42
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gitstr/modern-cpp-tutorial.git
git@gitee.com:gitstr/modern-cpp-tutorial.git
gitstr
modern-cpp-tutorial
modern-cpp-tutorial
master

搜索帮助