什么是 ISO C++直接定义转换函数来引用数组的方法?
根据标准,转换函数有一个 function-id operator
conversion-type-id,例如,operator char(&) [4]
我相信。但我不知道将函数参数列表放在哪里。 gcc 不接受 operator char(&())[4]
或 operator char(&)[4]()
或我能想到的任何东西。
现在,gcc 似乎接受 (&operator char ())[4]
但 clang 不接受,而且我也倾向于不接受,因为它似乎不符合我理解的语法。
我不想使用 typedef
因为我想避免它污染命名空间。
According to the standard, a conversion function has a function-id operator
conversion-type-id, which would look like, say, operator char(&)[4]
I believe. But I cannot figure out where to put the function parameter list. gcc does not accept either of operator char(&())[4]
or operator char(&)[4]()
or anything I can think of.
Now, gcc seems to accept (&operator char ())[4]
but clang does not, and I am inclined to not either, since it does not seem to fit the grammar as I understand it.
I do not want to use a typedef
because I want to avoid polluting the namespace with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用身份
您是正确的,函数和数组声明符在转换函数中不起作用。 本问题报告。不过,我认为 C++0x 已经为他们在那里讨论的内容提供了一个解决方案,
与
identity
和typedef
方法不同,这允许T
和 <我认为要推导出code>N。You can use identity
You are correct that function and array declarators won't work in conversion functions. This is also known and discussed in this issue report. However i think that C++0x already provides a solution to what they discuss there
Unlike the
identity
andtypedef
approach, this allowsT
andN
to be deduced, i think.C++ 没有为此提供语法。这是您必须使用类型的 typedef 名称的情况之一。
为了避免污染命名空间,在类内部声明 typedef-name 是完全可以的
C++ provides no syntax for that. This is one of those cases when you have to use a typedef-name for the type.
In order to avoid polluting the namespace, it is perfectly OK to declare the typedef-name inside the class