简体   繁体   English

C ++编译器不喜欢“使用INLINE = extern内联”

[英]C++ compiler does not like “using INLINE = extern inline”

There is a lot of information out there on the use of inline and how to properly do so for the desired intent such as here (which I am currently using as a reference) Inline Functions in C . 关于inline的使用以及如何针对所需的意图正确地进行操作,这里有很多信息,例如,这里(我目前用作参考) 是C中的内联函数

When I attempt to implement what is speficied in the page I get compiler errors for 当我尝试实现页面中指定的内容时,出现以下错误:

using INLINE = extern inline;

and even just 甚至只是

using INLINE = extern;

The compiler says "expected type specifier before extern" 编译器说“ extern之前的预期类型说明符”

What I'm wondering is why can I use using this way? 我想知道为什么我可以using这种方式?

Is it because using is really just reserved for types and substitutions? 是因为using实际上仅保留用于类型和替换吗?

Post Answer 发表答案

Thank you so much! 非常感谢! I totally missed the fact that I was reading through C reference. 我完全错过了我正在阅读C参考的事实。 This is good news as it didn't seem like there was a really good way to deal with things from what I was reading but it is probably that way as it is out of date compared to what they are doing in C++11 now. 这是个好消息,因为似乎没有一种真正好方法来处理我正在阅读的内容,但与现在在C ++ 11中所做的相比,它可能已经过时了。

Is it because using is really just reserved for types and substitutions? 是因为using实际上仅保留用于类型和替换吗?

I don't know what you mean by substitutions, but yes to the reservation for types. 我不知道您所说的替代是什么意思,但是对类型的保留是肯定的。 An alias declaration is for declaring new names for types . 别名声明用于声明类型的新名称。 A pair of specifiers doesn't form a type. 一对说明符不构成类型。 You can't even make it work by superficially adding a type name there, since the extern and inline specifiers only apply to object and function identifiers, and not their associated type. 您甚至不能通过在表面上添加类型名称来使其工作,因为externinline说明符仅适用于对象和函数标识符,而不适用于它们的关联类型。

The article uses a macro ( #define ) because token substitution is the only way to create user defined specifiers like you want to do. 本文使用宏( #define ),因为令牌替换是创建用户想要的说明符的唯一方法,就像您想要的那样。

It's also worth noting that in C++ inline and extern inline are the same thing. 还值得注意的是,在C ++ inlineextern inline是同一回事。 It's only in C (a different language to C++, and the subject of the linked article) that inline doesn't imply linkage, requiring you to specify extern . inline并不意味着必须使用C(与C ++不同的语言,以及链接文章的主题) inline并不意味着链接,需要您指定extern

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

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