Advertisement Jump to content
Sign in to follow this  
Alpha_ProgDes

void WTF (how*& implement)

This topic is 4904 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!