I have written I/O operations for pointers to objects of class Foo.
How do I improve these functions so that two equal pointers written to a stream can be later read as two equal pointers?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 : ""); }




Reply With Quote