void WTF (how*& implement)

Started by
2 comments, last by Fruny 18 years, 8 months ago
i have no idea how to approach this sort of function or even what to pass to it. here's a better example:

istream& operator >>(istream& in, PhoneCall*& phoneCall) {
    
    //is this right?
    //interval is a private member of the class 
    //two values from a file will be read and placed
    //in interval... later
    in >> phoneCall->interval;
    
    return in;
}

PhoneCall aCall;
PhoneCall* anotherCall;

cin >> //which variable, how and why

Beginner in Game Development?  Read here. And read here.

 

Advertisement
You would use anotherCall but it'd be a bad idea. Streaming in pointers is extremely non-intuitive. Prefer rewriting the extraction operator to do an ordinary reference.
a little more info (and example) if you please....

i'm googling but finding nothing.

Beginner in Game Development?  Read here. And read here.

 

struct PhoneCall{  std::string number;  unsigned int minutes;};std::istream& operator>>(std::istream& is, PhoneCall& call){   is >> call.number;   is >> call.minutes;   return is;}std::ostream& operator<<(std::ostream& os, const PhoneCall& call){   os << call.number;   os << ' '; // Don't forget the field separator!   os << call.minutes;   return os;}PhoneCall call;std::cin >> call;std::cout << call;
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement