![](/img/trans.png)
[英]Can someone tell me why am i getting this error even though the arguments are correct?
[英]Can someone tell me why I get this error message? inline constexpr variable
我從這里按照教程https://www.learncpp.com/cpp-tutorial/global-constants-and-inline-variables/
主文件
#include <iostream>
#include "constants.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
std::cout << "Enter a radius: ";
int radius{};
std::cin >> radius;
std::cout << "The circumference is: " << 2 * radius * constants::pi;
return 0;
}
常量.h
#ifndef CONSTANTS_H
#define CONSTANTS_H
// define your own namespace to hold constants
namespace constants
{
inline constexpr double pi { 3.14159 }; // note: now inline constexpr
inline constexpr double avogadro { 6.0221413e23 };
inline constexpr double my_gravity { 9.2 }; // m/s^2 -- gravity is light on this planet
// ... other related constants
}
#endif
錯誤消息 g++11:
error: 'constants::pi' declared as an 'inline' variable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.