Static Inline Variables in C++17
In this lesson, you’ll see how to enhance and simplify code using inline variables from C++17.
We'll cover the following
Motivation for inline variables
In C++11/14, if you wanted to add a static data member to a class, you needed to declare it and define it in a corresponding CPP file.
For example:
// a header file:
struct OtherType {
static int classCounter;
// ...
};
// implementation, cpp file
int OtherType::classCounter = 0;
As you can see above, classCounter
is an int
and you have to write it twice: in a header file and then in the CPP file.
Get hands-on with 1400+ tech skills courses.