c++17 inline variable

tmp.h

#pragma once
//内联变量测试
//头文件 放入一个全局对象
//情形 被多次重复包含 会报链接错误
//传统解决办法: 静态常量全局变量,静态成员函数放入静态局部变量,模板类型
// https://blog.csdn.net/janeqi1987/article/details/100108589
//c++ 17提供的解决方案, 内联变量 ,变量前加inline


struct CPP 
{
int a;

};

//c++ 17 内联变量
inline CPP a;

tmp.cpp

#include "tmp.h"
View Code
原文地址:https://www.cnblogs.com/yang131/p/13570281.html