Impossible to fully qualify class-name in out-of-class declarator of function definition

做~自己de王妃 提交于 2019-12-08 16:22:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!