Wrong variable is changed

I'm posting this problem in the Beginners section in case this is stupidly easy to answer.
My problem is with the following code snippet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Collision XY, TXY;

		CollisionDetection iDetectionShape[1];
		iDetectionShape[0] = FirstType;

		Formula			FormulaUsed[1];
		FormulaUsed[0] = 0;
		TRI				Position[1];
		bool				Interact[1];
		Interact[0] = true;
		int NumElem = 1;
		
		XY.DetectionShape	 = iDetectionShape;//XY is assigned here
		XY.FormulaUsed		=TXY.FormulaUsed= FormulaUsed;
		XY.Position			=TXY.Position= Position;
		XY.Interact			 =TXY.Interact= Interact;
		XY.NumElem = TXY.NumElem = NumElem;

		iDetectionShape[0] = SecondType;// but XY gets reassigned here
		TXY.DetectionShape = iDetectionShape;


The DetectionShape Variables are the problem. When the pointer XY.DetectionShape is set equal to the array iDetectionShape, XY.DetectionShape points to '3'(the value of FirstType. But when iDetectionShape[0] is set equal to SecondType (value = 1), XY.DetectionShape is also changed to 1.

I thinking an array is out of bounds but for the moment I don't see where.
Well you madea pointer assignment at line 13. What did you expect? You then changed iDetectionShape[0] to a new value so of course XY.DetectionShape is still pointing to the same array that you just changed.

Assigning the name of an array results in a pointer assignment, not a deep copy of the array. I do not understand why you would assign the address of a stack array anyhow. I also don't understand why you want an array with a size of 1.
Knew I was forgetting something basic, been awhile since I read my c++ book. I was trying for super simple to test out a function I wrote. Guess I went too simple. * embarrassed face*
Topic archived. No new replies allowed.