0

I was programming in c++ and I came across an issue. I had a struct for the player in a header file and wanted to use the struct in two different files.

 struct {
    float x;
    float y;

} player;

I tried many things and I did much research but it always resulted in errors or the variables not updating throughout all the files. However I made a discovery, you can use

inline struct EXPORT {
    float x;
    float y;

} player;

(c++17) Ive looked online and I cant find anyone talking about this, ive even searched "inline struct EXPORT" on github and no code results came up. I wonder if ive made a discovery. I am wondering if this is a known syntax and if it is a good idea to use such a function.

J. Doe
  • 171
  • 4
  • 11
  • 3
    This looks like an [inline variable](https://en.cppreference.com/w/cpp/language/inline). The fact that the struct happens to be named `EXPORT` is not really relevant and probably explains why that exact search term hasn't yielded any results for you. – Nathan Pierson Jan 10 '22 at 04:24
  • Try change `EXPORT` to something else, like `Player`. Does it change anything? – Ranoiaetep Jan 10 '22 at 04:32
  • One strange thing about your search is combining "inline" and "struct". Since the `inline` keyword serves no purpose when applied to a type definition, searches for "inline struct" could be expected to find something like [Inline struct declaration](https://stackoverflow.com/questions/7723887/), where "inline" is descriptive, not the keyword. It might have helped if you realized that it is the variable, not the type, that you are marking `inline`, because searching for "inline variable" turns up [How do inline variables work?](https://stackoverflow.com/questions/38043442/) as the second hit. – JaMiT Jan 10 '22 at 05:48

1 Answers1

1

am wondering if this is a known syntax

Yes. The syntax of variable and class definition is known. In this case, you define an inline variable named player which is of a class type named EXPORT.

There is no "exporting" involved here.

eerorika
  • 232,697
  • 12
  • 197
  • 326