Re: storing location, to variables, one return type


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by John Kugelman on April 19, 2001 at 14:35:11:

In Reply to: storing location, to variables, one return type posted by Nathan on April 18, 2001 at 20:58:20:

There are three practical ways to do this.

  1. Use two different accessors, like x() and y().

  2. Use reference parameters and store the coordinates in them. For example:

    void location (int &x, int &y);

    This is pretty simple to use, except that it requires you to have two variables to store the results in.

  3. The other option is to use a pair template, which is part of the STL. This is a nice solution because it is explicit that you are returning something. And if the template name is too long you can hide it behind a typedef, as in

    typedef pair < int, int > Location;




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]