Я следую инструкциям отсюда https://www.learncpp.com/cpp-tutorial/global-constants-and-inline-variables/
main. cpp
#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;
}
constants.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