H
Hal Vaughan
If I have object A, B, and C, all from separate classes and I create A, then
inside A, I create B, then I want to pass B to C, I know if I do
that "normally" what I get in C is actually a copy of B, not the original,
so if C modifies something in its copy of B, it doesn't effect A's copy of
B.
I've been experimenting using a reference and a pointer so I can pass B from
A to C and both will end up using the same copy of B, but I can't get it to
work. I'm sure this is so simple I'll feel like a complete idiot when I'm
done, but I just can't get it to work.
I've tried using this in C:
ObjB objb;
void setobj(ObjB* obj) {
objb = *obj;
return;
}
I've also tried replacing the first line of the function as the same, but
without an asterisk. I'm calling the function in A like this:
objc.setobj(&objb);
I would think that I'm passing a reference to objb from A to C, then all I'd
have to do is tell C that its objb is where the pointer points, but I can't
get it to work. I need for both A and C to be using the same instance of
B.
What am I doing wrong and what do I need to do instead?
Thanks!
Hal
inside A, I create B, then I want to pass B to C, I know if I do
that "normally" what I get in C is actually a copy of B, not the original,
so if C modifies something in its copy of B, it doesn't effect A's copy of
B.
I've been experimenting using a reference and a pointer so I can pass B from
A to C and both will end up using the same copy of B, but I can't get it to
work. I'm sure this is so simple I'll feel like a complete idiot when I'm
done, but I just can't get it to work.
I've tried using this in C:
ObjB objb;
void setobj(ObjB* obj) {
objb = *obj;
return;
}
I've also tried replacing the first line of the function as the same, but
without an asterisk. I'm calling the function in A like this:
objc.setobj(&objb);
I would think that I'm passing a reference to objb from A to C, then all I'd
have to do is tell C that its objb is where the pointer points, but I can't
get it to work. I need for both A and C to be using the same instance of
B.
What am I doing wrong and what do I need to do instead?
Thanks!
Hal