Click here to Skip to main content
16,005,080 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 1:48
Iain Clarke, Warrior Programmer30-Sep-08 1:48 
GeneralRe: dynamic allocation of arrays Pin
Sauce!30-Sep-08 2:16
Sauce!30-Sep-08 2:16 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 3:21
Iain Clarke, Warrior Programmer30-Sep-08 3:21 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!30-Sep-08 5:01
Sauce!30-Sep-08 5:01 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 5:31
Iain Clarke, Warrior Programmer30-Sep-08 5:31 
GeneralRe: dynamic allocation of arrays Pin
Sauce!30-Sep-08 5:43
Sauce!30-Sep-08 5:43 
GeneralRe: dynamic allocation of arrays Pin
Iain Clarke, Warrior Programmer30-Sep-08 6:02
Iain Clarke, Warrior Programmer30-Sep-08 6:02 
GeneralRe: dynamic allocation of arrays Pin
Sauce!2-Oct-08 5:05
Sauce!2-Oct-08 5:05 
I've been thinking hard about this and the only thing I can think of that might cause this problem is my constructors (the default constructor and a second constructor that takes two parameters.

Block::Block(void)
{
	Grounded = false;
	Shape = (rand() % 7);
	Colour = (rand() % 6);

	p_TileArray = NULL;
	p_TileArray = new Tile[4];

	p_TileArray[0].SetPos(498.0, 82.0);
	p_TileArray[1].SetPos(530.0, 82.0);
	p_TileArray[2].SetPos(498.0, 114.0);
	p_TileArray[3].SetPos(530.0, 114.0);
}

Block::Block(int itsShape, int itsColour)
{
	Grounded = false;
	Shape = itsShape;
	Colour = itsColour;

	p_TileArray = NULL;
	p_TileArray = new Tile[4];

	switch(Shape)
	{
	case SHAPE_O:
		{
			p_TileArray[0].SetPos(498.0, 82.0);
			p_TileArray[1].SetPos(530.0, 82.0);
			p_TileArray[2].SetPos(498.0, 114.0);
			p_TileArray[3].SetPos(530.0, 114.0);
			break;
		}

	case SHAPE_T:
		{
			p_TileArray[0].SetPos(530.0, 82.0);
			p_TileArray[1].SetPos(498.0, 114.0);
			p_TileArray[2].SetPos(530.0, 114.0);
			p_TileArray[3].SetPos(562.0, 114.0);
			break;
		}

	case SHAPE_L:
		{
			p_TileArray[0].SetPos(498.0, 114.0);
			p_TileArray[1].SetPos(530.0, 114.0);
			p_TileArray[2].SetPos(562.0, 114.0);
			p_TileArray[3].SetPos(562.0, 82.0);
			break;
		}

	case SHAPE_J:
		{
			p_TileArray[0].SetPos(498.0, 82.0); 
			p_TileArray[1].SetPos(498.0, 114.0);
			p_TileArray[2].SetPos(530.0, 114.0);
			p_TileArray[3].SetPos(562.0, 114.0);
			break;
		}

	case SHAPE_S:
		{
			p_TileArray[0].SetPos(466.0, 82.0);
			p_TileArray[1].SetPos(498.0, 82.0);
			p_TileArray[2].SetPos(466.0, 114.0);
			p_TileArray[3].SetPos(498.0, 82.0);
			break;
		}

	case SHAPE_Z:
		{
			p_TileArray[0].SetPos(466.0, 82.0);
			p_TileArray[1].SetPos(498.0, 82.0);
			p_TileArray[2].SetPos(466.0, 114.0);
			p_TileArray[3].SetPos(498.0, 82.0);
			break;
		}
		
	case SHAPE_I:
		{
			p_TileArray[0].SetPos(466.0, 82.0);
			p_TileArray[1].SetPos(498.0, 82.0);
			p_TileArray[2].SetPos(466.0, 114.0);
			p_TileArray[3].SetPos(498.0, 82.0);
			break;
		}

	default:
		{
			//error
			break;
		}
	}
}

Block::~Block(void)
{
	delete [] p_TileArray;
	p_TileArray = NULL;
}


AFAIK the rest of the class doesn't matter for this problem so I'll leave it out.

The line I'm concerned with is p_TileArray = new Tile[4]; in both constructors. Only one constructor will ever be called for each instance of the class, so theoretically this shouldn't be a problem, but theory is rarely an actuality :P Is there any way this could be causing me problems? I've done a bit of fiddling around with that bit hoping to fix it by trial and error but still I've got nothing to show for the time I've invested in it Frown | :(
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 2:42
Sauce!4-Oct-08 2:42 
GeneralRe: dynamic allocation of arrays Pin
Sauce!4-Oct-08 5:19
Sauce!4-Oct-08 5:19 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 5:34
Sauce!4-Oct-08 5:34 
GeneralRe: dynamic allocation of arrays [modified] Pin
Sauce!4-Oct-08 12:53
Sauce!4-Oct-08 12:53 
GeneralRe: dynamic allocation of arrays Pin
Sauce!17-Oct-08 20:58
Sauce!17-Oct-08 20:58 
Questionno WM_MOUSEHOVER in an edit Pin
followait28-Sep-08 18:58
followait28-Sep-08 18:58 
AnswerRe: no WM_MOUSEHOVER in an edit Pin
Iain Clarke, Warrior Programmer30-Sep-08 0:25
Iain Clarke, Warrior Programmer30-Sep-08 0:25 
QuestionCListCtrl Problem Pin
Dhiraj kumar Saini28-Sep-08 18:53
Dhiraj kumar Saini28-Sep-08 18:53 
AnswerRe: CListCtrl Problem Pin
_AnsHUMAN_ 28-Sep-08 18:59
_AnsHUMAN_ 28-Sep-08 18:59 
AnswerRe: CListCtrl Problem Pin
Naveen28-Sep-08 19:01
Naveen28-Sep-08 19:01 
QuestionWrite a buffer to stringstream Pin
CodingLover28-Sep-08 18:43
CodingLover28-Sep-08 18:43 
AnswerRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:04
Naveen28-Sep-08 19:04 
GeneralRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 19:08
CodingLover28-Sep-08 19:08 
GeneralRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:26
Naveen28-Sep-08 19:26 
NewsRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 19:35
CodingLover28-Sep-08 19:35 
GeneralRe: Write a buffer to stringstream Pin
Naveen28-Sep-08 19:54
Naveen28-Sep-08 19:54 
GeneralRe: Write a buffer to stringstream Pin
CodingLover28-Sep-08 20:18
CodingLover28-Sep-08 20:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.