[computer-go] C++ pointer question

House, Jason J. jhouse at mitre.org
Tue Aug 8 12:31:38 PDT 2006


The correct code would be something to the effect of
  *this = temp;  // this is a pointer and temp is not

Depending on the finer details of your class, you'll likely need to
define your own assignment operator (where the same loop you gave would
be written).
 

________________________________

	From: computer-go-bounces at computer-go.org
[mailto:computer-go-bounces at computer-go.org] On Behalf Of Peter Drake
	Sent: Tuesday, August 08, 2006 2:55 PM
	To: Computer Go
	Subject: [computer-go] C++ pointer question
	
	
	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/





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://computer-go.org/pipermail/computer-go/attachments/20060808/bacaa8d1/attachment.htm


More information about the computer-go mailing list