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
void WTF (how*& implement)
i have no idea how to approach this sort of function or even what to pass to it.
here's a better example:
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.
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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement