Thread: strange auto_ptr error

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    strange auto_ptr error

    In the following programme I'm using the auto_ptr pointer. All is good but when I try to print the value of the pointer, it prints out some memory location. Why?

    Code:
    #include <iostream>
    #include <memory>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        auto_ptr<int> number(new int);
        *number = 1;
        cout << "My number is " << number.get() << endl;
        
        cin.get();
        return(0);
    }

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    auto_ptr::get() returns the value of the pointer which is the location that the object is stored. Your printing out the memory location of the object.

    to get the actual value u already know how to do it

    Code:
    cout << "My number is " << *number << endl;

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    13
    oooh )
    Tnx.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    ooppps sorry wrong thread :S

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM