0

Quick question regarding the Fraction class created in the header file. Someone in my group used this in the header and I was wondering if there was an alternative to coding it than what they used. Something simpler for me to understand. It seems they just took a shortcut.

public:
    Fraction(int _num = 0, int _den = 1, char _sign = 'p') : numerator(_num), denominator(_den), sign(_sign) {}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by wyett
1

Another way to write this would be:

class Fraction
{
	int numerator;
	int denominator;
	char sign;
	public:
	Fraction(int _num = 0, int _den = 1, char _sign = 'p');
};

Fraction::Fraction(int _num, int _den, char _sign)
{
	numerator = _num;
	denominator = _den;
	sign = _sign;
}
Fraction(int _num = 0, int _den = 1, char _sign = 'p');

Having the '=' operator in the first declaration of the function makes it so if you do not give that parameter a value it will use the value stated as the default.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.