Riverreed Ward
Riverreed Ward

Reputation: 25

Using const variables through multiple header files

How could I share a constant value that is needed by multiple header files? Or is there some other way around this? What is considered the standard, or is it just preference?

Upvotes: 0

Views: 172

Answers (1)

NathanOliver
NathanOliver

Reputation: 180500

If the variable can be initialized with a constant expression, use

inline constexpr type name = value;

If not, then

inline const type name = value;

The inline keyword allows for the variable to be defined in multiple translation units and not be a violation of the one definition rule

Upvotes: 2

Related Questions