-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.h
More file actions
22 lines (18 loc) · 857 Bytes
/
constants.h
File metadata and controls
22 lines (18 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// global constants as external variables:
// Advantages:
// Works prior to C++16.
// Only one copy of each variable is required.
// Only requires recompilation of one file if the value of a constant changes.
// Downsides:
// Forward declarations and variable definitions are in separate files, and must be kept in sync.
// Variables not usable in constant expressions outside of the file in which they are defined.
#ifndef ECONSTANTS_H
#define ECONSTANTS_H
namespace ExternalConstants {
// Since the actual variables are inside a namespace, the forward declarations need to be inside a namespace as well
// We can't forward declare variables as constexpr, but we can forward declare them as (runtime) const
extern const double pi;
extern const double avogadro;
extern const double myGravity;
} // namespace ExternalConstants
#endif