Skip to content

SF.2 allow inline variables and static inline class member variables #2169

Open
@sgilbertson

Description

@sgilbertson

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions