C++ objects behave upon assignment

This is a discussion on C++ objects behave upon assignment within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am trying to understand how C++ object behave in the following case. I declare a handle using windows ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    27

    C++ objects behave upon assignment

    Hello,
    I am trying to understand how C++ object behave in the following case.

    I declare a handle using windows HDC as follows: HDC myHDC.

    version 1:
    My function is delcared as follows:
    Code:
    BMManager::BMManager(HDC _hdc) {
    	myHDC=_hdc;
    }
    version 2:
    Code:
    BMManager::BMManager(HDC &_hdc) {
    	myHDC=&_hdc;
    }
    In both version, the declaration for myHDC remains the same. The compiler did not complain on any error.
    Question1: Why would myHDC by treated differently between version 1 and version 2? After all, upon assignment the object declared remains the same.

    I would assume that version 1 says that is copy assignment, so all values in HDC is copyied. Perhaps handles are not object?????
    In version 2, myHDC points to an address of _hdc????

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    A HDC is of type 'void pointer' [void* ] and not an object (as are all HANDLE variables).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SetTimer() doesn't behave.
    By OnionKnight in forum Windows Programming
    Replies: 9
    Last Post: 04-09-2007, 03:52 PM
  2. OpenGL - Lights behave strangely
    By Frobozz in forum Game Programming
    Replies: 5
    Last Post: 06-06-2004, 02:00 PM
  3. Why does it behave so
    By mudigonda_ms in forum C Programming
    Replies: 6
    Last Post: 12-21-2003, 12:54 AM
  4. Two Struct & Class Programs that behave the same
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2002, 09:59 AM
  5. Why the function behave like that?
    By zahid in forum C Programming
    Replies: 1
    Last Post: 12-21-2001, 05:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21