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?
Member functions of a class can be defined either outside the class definition or inside the class definition. In both the cases, the function body remains the same, however, the function header is different.
A class declaration can appear inside the body of a function, in which case it defines a local class. The name of such a class only exists within the function scope, and is not accessible outside.
Member functions and static members can be defined outside their class declaration if they have already been declared, but not defined, in the class member list. Nonstatic data members are defined when an object of their class is created. The declaration of a static data member is not a definition.
A class declaration creates a unique type class name. A class specifier is a type specifier used to declare a class. Once a class specifier has been seen and its members declared, a class is considered to be defined even if the member functions of that class are not yet defined.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With