Salt_Peter
10/21/2008 5:02:00 PM
On Oct 21, 8:29 am, santiago <santiago10...@aol.com> wrote:
> On 2008-10-21 02:55:48 -0400, acehr...@gmail.com said:
>
> > On Oct 20, 11:33 pm, santiago <santiago10...@aol.com> wrote:
> >> I guess one cannot do this:
>
> > You need to be more specific because what you show is fine:
>
> >> arraytot[x][y] = arraytot[x][y] + arraydet[x][y];
>
> > That adds arraydet[x][y] to arraytot[x][y]. Written more readably:
>
> > arraytot[x][y] += arraydet[x][y];
>
> Yea. I tried that. It didn't work either.
>
>
>
> >> So, what's the trick to adding arrays like this?
>
> > Are you really trying to add two arrays? Is it defined as adding
> > corresponding elements? Then you can do it by adding the elements one
> > by one in a loop.
>
> Actually, C++ will not let you add two array elements like that (I am
> doing it from a loop, but
> just pulled out the line that C++ does not like). The error it generates is:
>
> error C2110: '+' : cannot add two pointers
>
> What I'm trying to do is accumulate totals from one array (storing the
> result in a total array, so it'd be more accurate to say I'm trying to
> add the elements together.
>
Umm, no. If you are getting 'cannot add two pointers' then you arent
adding elements together. Maybe you are trying to add the contents at
those pointers together? In which case one dereferences the pointer:
*(arraytot[x][y])
I'm baffled as to how you've exposed your problem.
That is:
arraytot[x][y];
is not legal (assuming x and y are integer constants).
But these are:
int arraytot[x][y];
int* arraytot[x][y];
Which is it?