Click to See Complete Forum and Search --> : I/O on object pointers.


judge
April 14th, 2005, 11:06 PM
I have written I/O operations for pointers to objects of class Foo.

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?

cilu
April 15th, 2005, 02:48 AM
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?

judge
April 15th, 2005, 03:19 AM
By two equal pointers I mean pointers x,y satisfying x == y. So yes, it means they both hold the same address.