问题
This program results in an undesired parsing greediness dead-end:
struct float4x4 {};
class C
{
float4x4 M();
};
float4x4 ::C::M()
{
return float4x4{};
}
: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
{}
now all good.
So I take it we can't fully qualify the class-name when using heading-return-type declarator syntax?
回答1:
You can put brackets to disambiguate:
float4x4 (::C::M)()
{
return float4x4{};
}
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.
来源:https://stackoverflow.com/questions/58913331/impossible-to-fully-qualify-class-name-in-out-of-class-declarator-of-function-de