On Friday, July 31, 2020 at 8:21:01 PM UTC-5, Botond Ballo wrote:
> On Fri, Jul 31, 2020 at 9:00 PM <cpp....@gmail.com> wrote:
> 
> > Stupid: It is not stupid, it is a feature.
> >
> 
> Ah, you mean `static inline` has uses in C++17 that it didn't have in older
> versions?
> 
> I would appreciate an example (or a link to post etc.) so we can understand
> this better.
> 
> Thanks,
> Botond

Sure, before 17 you had to initialize static variable in cpp "encapsulated" 
code. So maybe you want to expose static data, specifically the way you 
initialized this static data, through your headers cause you want your API 
users to have access to read them and figure out things. 

Now, you can do that in your header file outside the class brackets. But if you 
included the header, in more than one user cpp file, the linker will complain 
with duplicated declaration of your static objects.

Now with inline static, you can initialize in the class declaration. Whenever 
may be the case you want your API users (if an API / Lirbary is what you are 
writing) to understand how's your static var is initialized.

A link to show what I mean: 
https://www.tutorialspoint.com/how-do-inline-variables-work-in-cplusplus-cplusplus17#:~:text=The%20static%20value%20is%3A%2010,the%20class%20using%20inline%20variables.

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to