如何打印输入输出参数?
import std.stdio;
void main()
{
foo(2);
return;
}
inout(int) foo(inout(int) x)
{
writeln(x);
return x;
}
编译器输出:
c:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(3881): Error: template instance Unqual!(__T4ImplTNgiZ) does not match template declaration Unqual(T)
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(757): Error: template instance std.conv.toTextRange!(inout(int), LockingTextWriter) error instantiating
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1708): instantiated from here: write!(inout(int), char)
x.d(11): instantiated from here: writeln!(inout(int))
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1708): Error: template instance std.stdio.File.write!(inout(int), char) error instantiating
x.d(11): instantiated from here: writeln!(inout(int))
x.d(11): Error: template instance std.stdio.writeln!(inout(int)) error instantiating
此外, to!string 不适用于 inout 参数。
更新:我刚刚发现(通过反复试验)以下方法有效:
writeln(cast(const)x);
这是正常的方法还是我错过了什么?