What causes the problem above?Code:// Object definition
...
int name;
void* hook; //the variable that holds the info
...
std::istream &operator>>(std::istream &stream, Object &o)
{
char temp[100];
stream >> name;
stream.getline(temp, 100);
o.hook = &temp;
// the following gives the output I want
std::cout << reinterpret_cast<const char *>(o.hook);
return stream;
}
std::ostream &operator<<(std::ostream &stream, const Object &o)
{
stream << name;
stream << reinterpret_cast<const char *>(o.hook);
return stream;
}
// Main program
...
Object object;
...
//the following gives garbage for "hook" only
std::cout << object;