c++17 - 如何在 Visual Studio 2019 上修复 E0325
问题描述
我正在尝试inline
在 Visual Studio 2019 v16.10.3 中使用说明符,但我不断收到此错误
E0325 inline specifier allowed on function declarations only
我正在使用 C++17 标准。有没有办法解决这个问题?
这是我的代码
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <iostream>
// define your own namespace to hold constants
namespace constants
{
inline constexpr int max_class_size{ 100};
}
#endif
这是“main.cpp”文件
#include "constants.h"
#include <iostream>
int main()
{
std::cout << "How many students are in your class? ";
int students{};
std::cin >> students;
if (students > constants::max_class_size){
std::cout << "There are too many students in this class";
}
else std::cout << "This class isn't too large";
return 0;
}
解决方案
推荐阅读
- angular - 有条件地设置输入类型
- apache - (help) 无法将代码 htaccess 更改为 nginx
- angular - cloudflare 和 angular 4 上的缓存错误未加载内容
- python - 在我看到 VS Code 中的任何内容之前运行“活动文件”关闭
- c++ - 如何将比较器作为函数的参数传递?
- javascript - 重置游戏逻辑
- sql - 将多列转置为行,查找哪些数据发生了变化,如果没有变化则保持旧值
- arrays - 指向二维数组中一行的可变指针
- python - PILLOW 图像模块无法在 Raspbian 的命令行中显示图像
- javascript - Stripe JS 卡片元素不允许用户在 Flask 中输入