help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error with Cell element access


From: Jaroslav Hajek
Subject: Re: Error with Cell element access
Date: Fri, 14 Aug 2009 06:55:06 +0200

On Thu, Aug 13, 2009 at 4:53 PM, Justin
Bare<address@hidden> wrote:
> I get the error "conversion from ‘int’ to non-scalar type ‘dim_vector’
> requested" on the line that says "cell_data(v) = var;" in the following
> code. I have included the octave library and Cell.h.
>
>    Cell cell_data(dim_vector(numVars));
>
>
>    for(int v = 0; v < numVars; v++){
>      int dataLength = myData.arrayVars[names[v]][0].size();
>
>      NDArray var = NDArray(dim_vector(numTimeSteps, dataLength));
>      for (int t = 0; t < numTimeSteps; t++){
>        for(int i = 0; i < dataLength; i++){
>          var(t, i) = myData.arrayVars[names[v]][t][i];
>
>        }
>      }
>      cell_data(v) = var;
>    }
>
>
> Any ideas?
> --
>

First of all, it would help a little if you always reduced your code
to as much self-contained example as possible, i.e. declare variables,
remove code not necessary to trigger the bug etc.

This is a very subtle problem in C++ syntax you're hitting. The statement

Cell cell_data(dim_vector(numVars));

is actually treated as a function prototype declaration (!)

Cell cell_data(dim_vector numVars);

because the parentheses can be discarded in this case. I can't quote
the standard now, but I've hit this several times before.
Either of the following should work:

Cell cell_data((dim_vector(numVars))); // extra parens

Cell cell_data = Cell(dim_vector numVars);

Cell cell_data (dim_vector (numVars, 1));

Cell cell_data (numVars, 1);

regards

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]