Jump to content
  • Advertisement
Sign in to follow this  
Alpha_ProgDes

void WTF (how*& implement)

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!