首页 > 解决方案 > 如何在 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;
} 

标签: c++17visual-studio-2019inline

解决方案


推荐阅读