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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    Code:
        if(rhInt.value == 0) {
    //  the right hand side points to nothing, so that we are equal later we should point
    //  to nothing therefore we set the pointer we are going to be using to nothing/null
            new_int = 0;
        } else {
    //  The right hand side points to something, we want to point to a different something 
    //  that is a copy of the other something therefor we set new_int to point to the result
    //  of calling new.
        new_int = new  // A new something but a new what?
                        int   // the type of the new something, we need to call a constructor
                           (  // what constructor?
                            * // we are dereferencing somthing this has type int. thus a
                              // construtor that takes a single value of type int, 
                              // int's copy ctor int::int(const int &other);
                              (rhInt.value) // what we are dereferencing, this has type
                                            // pointer to int
                      );
        }
    it's just shorter the other way.
    On edit: and Hunters version will actually work.
    Last edited by grib; 03-13-2005 at 05:45 PM. Reason: font dammage, acknowlage typo

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