www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing array as an function argument.

reply Vino.B <vino.bheeman hotmail.com> writes:
Hi All,

   Can some one help me on how to pass a container array as a 
function argument , the below code throws an error,

Error: Error: function T3.Test2 (Array!string t1) is not callable 
using argument types (RangeT!(Array!string))

import std.stdio: writeln;
import std.container;

auto Test2 (Array!string t1) {
return t1;
}

auto Test1 () {
auto Fs = Array!string("C:\\Temp\\TEST1\\BACKUP", 
"C:\\Temp\\TEST2\\EXPORT");
return Fs[];
}
void main () {
auto t1 = Test1[];
Test2(t1);
}

From,
Vino.B
Sep 11
parent reply wobbles <grogan.colin gmail.com> writes:
On Monday, 11 September 2017 at 11:58:18 UTC, Vino.B wrote:
 Hi All,

   Can some one help me on how to pass a container array as a 
 function argument , the below code throws an error,

 Error: Error: function T3.Test2 (Array!string t1) is not 
 callable using argument types (RangeT!(Array!string))

 import std.stdio: writeln;
 import std.container;

 auto Test2 (Array!string t1) {
 return t1;
 }

 auto Test1 () {
 auto Fs = Array!string("C:\\Temp\\TEST1\\BACKUP", 
 "C:\\Temp\\TEST2\\EXPORT");
 return Fs[];
 }
 void main () {
 auto t1 = Test1[];
 Test2(t1);
 }

 From,
 Vino.B
The type returned from Test1() is a `RangeT!(Array!string)`. This is due to the `[]` on the end of `Fs[]`. Remove the `[]` to just return a `Array!string`.
Sep 11
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Monday, 11 September 2017 at 12:03:32 UTC, wobbles wrote:
 On Monday, 11 September 2017 at 11:58:18 UTC, Vino.B wrote:
 Hi All,

   Can some one help me on how to pass a container array as a 
 function argument , the below code throws an error,

 Error: Error: function T3.Test2 (Array!string t1) is not 
 callable using argument types (RangeT!(Array!string))

 import std.stdio: writeln;
 import std.container;

 auto Test2 (Array!string t1) {
 return t1;
 }

 auto Test1 () {
 auto Fs = Array!string("C:\\Temp\\TEST1\\BACKUP", 
 "C:\\Temp\\TEST2\\EXPORT");
 return Fs[];
 }
 void main () {
 auto t1 = Test1[];
 Test2(t1);
 }

 From,
 Vino.B
The type returned from Test1() is a `RangeT!(Array!string)`. This is due to the `[]` on the end of `Fs[]`. Remove the `[]` to just return a `Array!string`.
Hi, If i remove the `[]` at the end of `Fs[]` I am getting the same error, if i remove the `[]` from the file "auto t1 = Test1[];" the out is empty. From, Vino.B
Sep 11
parent reply wobbles <grogan.colin gmail.com> writes:
On Monday, 11 September 2017 at 12:20:08 UTC, Vino.B wrote:
 On Monday, 11 September 2017 at 12:03:32 UTC, wobbles wrote:
 On Monday, 11 September 2017 at 11:58:18 UTC, Vino.B wrote:
 [...]
The type returned from Test1() is a `RangeT!(Array!string)`. This is due to the `[]` on the end of `Fs[]`. Remove the `[]` to just return a `Array!string`.
Hi, If i remove the `[]` at the end of `Fs[]` I am getting the same error, if i remove the `[]` from the file "auto t1 = Test1[];" the out is empty. From, Vino.B
This works: https://dpaste.dzfl.pl/1fd9021739ad
Sep 11
parent Vino.B <vino.bheeman hotmail.com> writes:
On Monday, 11 September 2017 at 12:44:00 UTC, wobbles wrote:
 On Monday, 11 September 2017 at 12:20:08 UTC, Vino.B wrote:
 On Monday, 11 September 2017 at 12:03:32 UTC, wobbles wrote:
 On Monday, 11 September 2017 at 11:58:18 UTC, Vino.B wrote:
 [...]
The type returned from Test1() is a `RangeT!(Array!string)`. This is due to the `[]` on the end of `Fs[]`. Remove the `[]` to just return a `Array!string`.
Hi, If i remove the `[]` at the end of `Fs[]` I am getting the same error, if i remove the `[]` from the file "auto t1 = Test1[];" the out is empty. From, Vino.B
This works: https://dpaste.dzfl.pl/1fd9021739ad
Hi Wobbles, Thank you very much, that solved my problem. From, Vino.B
Sep 11