|
-
April 14th, 2005, 11:06 PM
#1
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?
-
April 15th, 2005, 02:48 AM
#2
Re: I/O on object pointers.
 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?
-
April 15th, 2005, 03:19 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|