Open
Description
SF.2 has a list under "A header file must contain only" that does not include:
static inline
class member variables (not just functions)inline
variables not in a class declaration (again, not just functions)
Both are supported since C++17, resulting in all translation units linking the entity to the same memory location, The first point above results in code simplification and allows implementation of header-only classes that would otherwise not be possible. In [https://en.cppreference.com/w/cpp/language/inline](inline specifier - cppreference.com):
An inline function or variable(since C++17) ... has the same address in every translation unit.
For example, if a header includes:
class MyClass
{
public:
static inline int staticInlineMember = 5;
};
inline int inlineVariable = 5;
The memory location of staticInlineMember
is always the same, when that header is included in multiple source files. So is the location of inlineVariable
.
Metadata
Metadata
Assignees
Labels
No labels