overloaded functions question.. is this correct?

My instructor gave us a review for a test we have tomorrow and I'm looking at a problem and it doesn't make sense.. Can someone let me know what they think? The only thing that doesn't look right is that it doesn't have any parameters that its taking in...? Isn't that the only thing wrong?
The question says:

"Find as many errors as you can in the following overloaded function definitions."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int getValue()
{
	int inputValue;
	cout << " Enter an integer: ";
	cin >> inputValue;
	return inputValue;
}

double getValue()
{
	double inputValue;
	cout << " Enter a float point value: ";
	cin >> inputValue;
	return inputValue;
}

For a start:

Your functions are only different in the return type - That isn't overloading.
(the return type isn't important in overloading);

As you suspected - they must differ in their parameters.

Quick solution - pass a reference like this:

1
2
3
4
5
void getValue(int &inputValue)
{
	cout << " Enter an integer: ";
	cin >> inputValue;
}



You can do the other(s)
Last edited on
Topic archived. No new replies allowed.