| |
| Posted by J C Calvarese in reply to Glenn M. Lewis | PermalinkReply |
|
J C Calvarese
Posted in reply to Glenn M. Lewis
| Glenn M. Lewis wrote:
> I have the following class:
I had to add some lines to get it to compile. (You didn't give us a compilable example to work with.)
Here's a complete example that does compile:
class Program
{
char[] code;
int fitness;
int index;
int sortval;
}
static void crossover(Program p, Program p1)
{
int n;
int i;
int j;
//...
// memcpy(p.code + i, p1.code + j, n);
char[] tmp = p.code[j..(j+n)];
p.code.length = i + n; // COMPILER ERROR
p.code[i..(i+n)] = tmp[];
}
void main()
{
Program myP = new Program();
Program myP1 = new Program();
crossover(myP, myP1);
}
>
> class Program
> {
> char[] code;
> int fitness;
> int index;
> int sortval;
> }
>
> At one point, I am trying to change the length of the 'code' array, like so:
>
> static void crossover(Program p, Program p1)
> {
> int n;
> int i;
> //...
I'm going to go out of a limb here and guess this is where the error is.
I'm going to go even farther out on a limb and guess you have something like this in there: p.code.length++;
If so, you'll have to change it to: p.code.length = p.code.length + 1;
If none of this helps, you might try posting a fuller example. I can't find anything wrong with the code you've posted. If I could duplicate your error, I might be able to fumble around into a solution.
> // memcpy(p.code + i, p1.code + j, n);
> char[] tmp = p.code[j..(j+n)];
> p.code.length = i + n; // COMPILER ERROR
> p.code[i..(i+n)] = tmp[];
> }
>
> I don't understand why I get the error message: 'p.code.length is not an lvalue'...
> I thought I could change the length of the array?
>
> Thanks!
> -- Glenn Lewis
--
Justin
http://jcc_7.tripod.com/d/
|