I'm not REALLY a newbie, but.......

From: as mellow as a horse (mail_at_MICKmoss42.fslife.co.uk)
Date: 06/01/04


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.



Relevant Pages

  • he should lay wildly if Henrys spread isnt deep
    ... Nowadays, valleys happen with legitimate ballets, unless they're efficient. ... To be passing or frightened will start informal memorandums to weakly commence. ... What will you account the rare integral emergencys before Hamid does? ...
    (sci.crypt)
  • Re: Southern Water...grrrr
    ... result I ended up with them passing 'my' account over to a debt ... account to a debt collectors being one of them. ... merging data earlier this year. ...
    (uk.local.kent)
  • Re: HELP with DateAdd statement and SQL
    ... making a mistake by passing the the time in UTC format. ... Using the sa account for applications is a major gaffe. ... This email account is my spam trap so I ...
    (microsoft.public.scripting.vbscript)
  • Re: Im not REALLY a newbie, but.......
    ... suffice to say it's just a simple bank account example type thing. ... > CBankAccount acc1; ... > But I'm passing pointers, so why is it acting like I'm passing by value? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [PATCH mm] fix swapoff breakage; however...
    ... Maybe unuse_pte should just let containers go over their limits without ... Or swap should be counted along with RSS? ... Account each RSS page with a probable swap cache page, ...
    (Linux-Kernel)

Loading