I'm not REALLY a newbie, but.......
From: as mellow as a horse (mail_at_MICKmoss42.fslife.co.uk)
Date: 06/01/04
- Next message: Ronen Kfir: "gets string to bidimensional array"
- Previous message: flavius: "Re: local/pointers ? HELP"
- Next in thread: marbac: "Re: I'm not REALLY a newbie, but......."
- Reply: marbac: "Re: I'm not REALLY a newbie, but......."
- Maybe reply: as mellow as a horse: "Re: I'm not REALLY a newbie, but......."
- Reply: Leor Zolman: "Re: I'm not REALLY a newbie, but......."
- Reply: as mellow as a horse: "Re: I'm not REALLY a newbie, but......."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 1 Jun 2004 21:04:00 +0100
I've been away from C++ for a few years and I'm just trying to reaqaint
myself by creating some simple console apps in VC.NET 2003
I'm having some problems with a function that simply swaps two objects. I
have some class code in a seperate header which I don't think I need to
show, suffice to say it's just a simple bank account example type thing. In
the main() function I create a couple of dynamic instances of this class.
Just for test purposes, all objects have the name "fred" automatically
assigned to it's 'account_holder' attribute. When creating the second
object I call a method to assign "james" to this attribute. I then simply
call the swap method which looks like this: (to avoid pasting html I've had
to hand write this which explains any typos)
void bank_swap(CBankAccount* first, CBankAccount* second) {
CBankAccount* temp = first;
first = second;
second = temp;
}
I know this function works (I've used some couts inside the function, and
it's hardly rocket science anyway!), but after returning to main(), and
printing the account holder names out, it still attributes fred to account1
and james to account2 instead of vice-versa. I could perfectly understand
this if I was using non-dynamic objects and passing by value eg.
CBankAccount acc1;
CBankAccount acc2;
bank_swap(acc1, acc2)
void bank_swap(CBankAccount a1, a2) {
// swap code
}
But I'm passing pointers, so why is it acting like I'm passing by value?
Please don't give me an alternative using C++ style pass-by-reference. I'm
just looking to get used to using pointers again first.
- Next message: Ronen Kfir: "gets string to bidimensional array"
- Previous message: flavius: "Re: local/pointers ? HELP"
- Next in thread: marbac: "Re: I'm not REALLY a newbie, but......."
- Reply: marbac: "Re: I'm not REALLY a newbie, but......."
- Maybe reply: as mellow as a horse: "Re: I'm not REALLY a newbie, but......."
- Reply: Leor Zolman: "Re: I'm not REALLY a newbie, but......."
- Reply: as mellow as a horse: "Re: I'm not REALLY a newbie, but......."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|