简体   繁体   English

在 c++ 中导出内联结构

[英]Exporting an inline struct in c++

I was programming in c++ and I came across an issue.我在 c++ 中编程时遇到了一个问题。 I had a struct for the player in a header file and wanted to use the struct in two different files.我在 header 文件中有一个播放器结构,并想在两个不同的文件中使用该结构。

 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. (c++17) 我在网上看了,我找不到任何人在谈论这个,我什至在 github 上搜索了“inline struct EXPORT”并且没有出现代码结果。 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.我想知道这是否是一种已知的语法,以及使用这样的 function 是否是个好主意。

am wondering if this is a known syntax我想知道这是否是已知的语法

Yes.是的。 The syntax of variable and class definition is known.变量和 class 定义的语法是已知的。 In this case, you define an inline variable named player which is of a class type named EXPORT .在这种情况下,您定义了一个名为player的内联变量,它是一个名为EXPORT的 class 类型。

There is no "exporting" involved here.这里不涉及“导出”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM