【发布时间】:2012-04-30 09:49:18
【问题描述】:
我已将这个问题浓缩为一个小的代表性样本:
import std.stdio;
class Foo
{
private int f;
}
class State
{
private Foo foo;
const Foo getFoo()
{
return foo; // This line here.
}
}
void main()
{
auto s = new State;
writeln(s.getFoo());
}
我把那个代码放在test.d。
$ gdmd test.d
test.d:13: Error: cannot implicitly convert expression (this.foo) of type const(Foo) to test.Foo
我知道它告诉我用cast(test.Foo)foo 转换返回值,但为什么呢?为什么它将成员解释为const(Foo) 类型,为什么需要我抛弃const?我觉得我在这里做错了什么。
【问题讨论】:
标签: d