无法在函数定义的类外声明符中完全限定类名 [英] Impossible to fully qualify class-name in out-of-class declarator of function definition
问题描述
此程序会导致不希望的解析贪婪的死角:
This program results in an undesired parsing greediness dead-end:
struct float4x4 {};
class C
{
float4x4 M();
};
float4x4 ::C::M()
{
return float4x4{};
}
:8:1:错误:'float4x4'中没有名为'C'的成员;你的意思仅仅是"C"吗?
float4x4 :: C :: M()
^ ~~~~~~~~~~~
:8:1: error: no member named 'C' in 'float4x4'; did you mean simply 'C'?
float4x4 ::C::M()
^~~~~~~~~~~~
可以使用尾随返回类型固定"哪些内容:
Which can be 'fixed' using trailing return type:
auto ::C::M() -> float4x4
{}
现在一切都好.
所以我认为在使用heading-return-type声明符语法时,我们不能完全限定类名吗?
So I take it we can't fully qualify the class-name when using heading-return-type declarator syntax?
推荐答案
您可以使用方括号消除歧义:
You can put brackets to disambiguate:
float4x4 (::C::M)()
{
return float4x4{};
}
虽然我使用gcc和clang(均为-pedantic
)进行了测试,但我不能真正告诉您什么规则可以使之正常运行,尽管并非没有括号.我更喜欢尾随返回类型.
I cannot really tell you what rule makes this ok, while it is not without the brackets, though I tested with gcc and clang (both -pedantic
). I would prefer the trailing return type.
这篇关于无法在函数定义的类外声明符中完全限定类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!