CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Posts
    5

    I/O on object pointers.

    I have written I/O operations for pointers to objects of class Foo.

    Code:
    typedef Foo *FooPtr;
    
    std::istream &operator>>(std::istream &is, FooPtr &foo_ptr)
    {
        bool is_null;
        if (!(is >> is_null))
            return is;
    
        if (is_null)
        {
            foo_ptr = 0;
            return is;
        }
    
        foo_ptr = new Foo();
        return is >> *foo_ptr;
    }
    
    std::ostream &operator<<(std::istream &os, FooPtr foo_ptr)
    {
        return os << (foo_ptr != 0) << " " << (foo_ptr ? *foo_ptr : "");
    }
    How do I improve these functions so that two equal pointers written to a stream can be later read as two equal pointers?

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: I/O on object pointers.

    Quote Originally Posted by judge
    How do I improve these functions so that two equal pointers written to a stream can be later read as two equal pointers?
    What do you mean two equal pointers? A pointer holds a memory location. So, do you mean two pointers that hold the same address?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jun 2004
    Posts
    5

    Re: I/O on object pointers.

    By two equal pointers I mean pointers x,y satisfying x == y. So yes, it means they both hold the same address.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured