2
私は 'const'参照を使ってグラフをたどるループを持っていますが、私が反復変数を割り当てると、それが非constであることが分かります。Dのconst参照を使ってグラフをたどることはできますか?
class ClassDescriptor
{
const string name;
const TypeInfo type;
const ClassDescriptor base;
const IPropertyDescriptor[string] propertiesByName;
IPropertyDescriptor getFlattenProperty(string name)
{
// This declaration makes 'const(ClassDescriptor) bag'
// Note that in this point I can't add ref keyword.
auto bag = this;
while(!(bag is null))
{
if(name in bag.propertiesByName)
{
return bag.propertiesByName[name];
}
// This assigment breaks the constness
bag = bag.base;
}
return null;
}
public this(string name, TypeInfo type, ClassDescriptor base, const IPropertyDescriptor[string] propertiesByName)
{
this.name = name;
this.type = type;
this.base = base;
this.propertiesByName = propertiesByName;
}
}
Proのヒント:while(bag!is null)と書くことができます。 inと同じです。感謝! – sigod
ありがとう! :)私は知らなかった –
私はDのプログラマーではないが、なぜあなたはポインタを使用できないのですか? – Elazar