Inferred return types
Jacob Carlborg
doob at me.com
Fri Jun 29 12:17:54 PDT 2012
I just noticed that the return type of a function can be inferred
without using a storage class:
@property foo ()
{
return "foo";
}
void main ()
{
string str = foo;
}
Is that supposed to work? The specification says:
"If it does not already have a storage class, use the auto storage class."
But @property is not a storage class. It seems I can put most of the
attributes there instead of @property, both those with and without a @.
Second, it seems it's not possible to override a method with an inferred
return type, as the example below shows:
class Foo
{
auto foo ()
{
return "Foo";
}
}
class Bar : Foo
{
auto foo ()
{
return "Bar";
}
}
void main ()
{
Foo f = new Bar;
writeln(f.foo());
}
Results in:
Error: function main.Bar.foo of type () overrides but is not covariant
with main.Foo.foo of type ()
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list