Monday, July 20, 2009

Named Constructor Idiom

you would like to overload constructor on same type argument.

class Rational
{
private:
int x, y;

static Rational rectangular(int, theX, theY)
{
return Rational(theX, theY);
}

static Rational polar(int userX, int userY)
{
return Rational(userX * angle, userY * angle);
}
};

No comments: