CPP: Multiple pointers to one heap object problem.
So while writing a game of mine, I ran into a problem that has mixed me up on how I thought pointers worked. I was just a little over 125% sure the following worked. So let me first explain a bit on how I see pointers working in one way, to see if someone can catch a problem if any.
Lets say you had two pointers: Code:
type* a = NULL; Code:
a = new type; Code:
a = b; Now the large code block labled 'MAIN TEST CODE' seems more or less the same to me. Except 'b' would point to what 'a' points to by the means of a member function of a class. Such as: Code:
class some_class My question is why? I was convinced before this and still am to some degree that I have done this before, but I can't find the code that proves this(I've lost some code over the past month so maybe it was there). Am I doing something wrong that I am oblivious to? Or am I wrong on me thinking that I have done this before? The following code I mentioned a couple times earlier roughly demonstrates in a condensed way how exactly my game operates at a certain point, where the problem lies. 'MAIN TEST CODE' Code:
#include <iostream> |
The error is here:
Code:
void set_data ( data* i ) There are two (and more) solutions to this situation, which will also most likely help explain why it doesn't work. Code:
// by pointer Code:
// by reference |
I see my error. Thank you.
|
All times are GMT -5. The time now is 04:55 AM. |