Thread: A homework problem about C++ (Pointer)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    thanks all^^

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    77

    Cool

    So, Should I use this part to switch with my old
    Code:
     
    Integer& Interger::operator=( const Interger& rhInt)
    {
             value = rhInt.value;
             return *this;
    }
    to that one

    Code:
    // call new before calling delete (safe for self assignment)
    Integer& Integer::operator=( const Integer& rhInt ) {
    // do not dereference a null pointer, consider a null pointer 
    // to be a  deep copy of a null pointer.  
        int *new_int = rhInt.value?new(*(rhInt.value)):0;
        delete value;
        value = new_int;
        return *this;
    but. what is it?

    Code:
     
    int *new_int = rhInt.value?new(*(rhInt.value)):0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A problem with pointer initialization
    By zyklon in forum C Programming
    Replies: 5
    Last Post: 01-17-2009, 12:42 PM
  2. Problem with function's pointer!
    By Tirania in forum C Programming
    Replies: 5
    Last Post: 11-28-2008, 04:50 AM
  3. printf output makes no sense. Is it a Pointer problem?
    By officedog in forum C Programming
    Replies: 3
    Last Post: 10-03-2008, 09:01 AM
  4. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  5. Pointer problem with FILE *f in function
    By mabuhay in forum C Programming
    Replies: 6
    Last Post: 02-14-2006, 04:15 PM