Here is my version which works:
Int_t fun(const Int_t n, Int_t x) {
Int_t* arr = new Int_t[n];
arr[n-1] = x;
Int_t ret = arr[n-1];
delete [] arr;
return ret;
}
void pass(Int_t k, Int_t x) {
for (Int_t i=1; i<=k ; i++)
cout << "fun(" <<i<<","<<x<<") = " << fun(i,x) << endl;
}
I think that Masa Goto is now hard thinking about this problem.
Radovan
Jiri Bystricky wrote:
>
> Hi,
> is anything wrong with the script 'test.C' (see below)?
> It gives (ROOT version 3.00/02):
>
> root [0] .L test.C
> root [1] cout << fun(1,5) << endl;
> 5
> root [2] cout << fun(2,5) << endl;
> 5
> root [3] pass(2,5)
> fun(1,5) = 5
> Error: Array index out of range arr -> [1] valid upto arr FILE:test.C LINE:8
> fun(2,5) = 0
> *** Interpreter error recovered ***
> root [4] cout << fun(2,5) << endl;
> Error: Array index out of range arr -> [1] valid upto arr FILE:/tmp/filevtC7Yq_cint
> LINE:2
> Error: Illegal pointer operation (tovalue) FILE:/tmp/filevtC7Yq_cint LINE:1
> *** Interpreter error recovered ***
>
> Cheers Jiri
> -----------------------------------------------------------------------------
> test.C
>
> Int_t fun(const Int_t n, Int_t x) {
> Int_t arr[n];
> arr[n-1] = x;
> return arr[n-1];
> }
> void pass(Int_t k, Int_t x) {
> for (Int_t i=1; i<=k ; i++)
> cout << "fun(" <<i<<","<<x<<") = " << fun(i,x) << endl;
> }
> -----------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET