2013-07-04 18 views
5

どのように出力パラメータを印刷できますか?入力パラメータの印刷方法は?

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 

また、文字列にINOUTパラメータでは動作しません。

アップデート:私はちょうど、次の作品のことを(試行錯誤で)出て見つけた:

writeln(cast(const)x); 

が、これは通常の方法ですか私は何かが足りないのですか?

+0

あなたの問題の解決策を見つけるのは役に立たないが、戻り値の型の前に 'inout'属性を付けて何を達成したいのですか?これが方法であれば、 'this'がinoutとして宣言されることを意味します。その場合、 'const'や' pure'を使うのと同じように、 'int foo(inout(int)x)inout'をやりたいと思います。これは自由な関数なので、 'inout(int)foo(inout(int)x)'のような意味を持つと仮定します。しかし、 'int'はプリミティブ型であり、とにかくコピーされるので、そのまま残すこともできます。コンパウンド/構築型では、これはまったく別の話です。 –

+0

あなたは絶対に正しいです、ありがとう、間違ったコードをコピーしました。私が達成したかったのは、inoutのパラメータに従ってinoutの戻り値の型がどのように変化するかをテストすることでした。 – gerleim

答えて

関連する問題