[computer-go] C++ pointer question

Lars Nilsson chamaeleon at gmail.com
Tue Aug 8 12:26:06 PDT 2006


Try "*this = temp;", assuming copying the memory area from one object
to another is correct (be careful with pointers, etc, if you've
allocated memory and the destructor releases it, unless you use
reference counting for these elements. Fixed sized arrays are not a
problem of course).

Lars Nilsson

On 8/8/06, Peter Drake <drake at lclark.edu> wrote:
>
> Okay, I've got this method in my BitBoard class:
>
> void dilate() // Expand to include all adjacent points
> {
> BitBoard temp;
> temp.bits[0] = bits[0] | (bits[0] << 1) | (bits[0] >> 1) | bits[1];
> temp.bits[board_width - 1] = bits[board_width - 1] | (bits[board_width - 1]
> << 1)
> | (bits[board_width - 1] >> 1) | bits[board_width - 2];
> for (unsigned row = 1; row < board_width - 1; row++) {
> temp.bits[row] = bits[row] | (bits[row] << 1) | (bits[row] >> 1) | bits[row
> - 1] | bits[row + 1];
> }
> for (unsigned row = 0; row < board_width; row++) {
> bits[row] = temp.bits[row];
> }
> }
>
> Is there some way to avoid that second for loop? I tried "this = temp" and
> "*this = *temp", but the compiler isn't happy with either.
>
> Thanks,
>
>
> Peter Drake
> Assistant Professor of Computer Science
> Lewis & Clark College
> http://www.lclark.edu/~drake/
>
>
>
>
>
> _______________________________________________
> computer-go mailing list
> computer-go at computer-go.org
> http://www.computer-go.org/mailman/listinfo/computer-go/
>
>


More information about the computer-go mailing list