[C++17] Inline Variable

in coding •  7 years ago 

Pattern

inline auto var = [value];


Description

C++ consist a lot of source files. They are compiled, linked into single binary file. When linking, it occurs error when you defined some symbols multiple time. The traditional solution is to declare symbol in the header files, then the definition will be done once for each source file which has included the header files. This is called One Definition Rule. In C++17, there is another way to solve this. inline keyword can be in front of variables. Compiler can implement variables by inline keyword, which the variable will be redefined where it is called.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!