Counter function

I am writing a class for a counter. There is a decreaseCount function in that class, which will decrease the count by 1 if the count is 1 larger, and do nothing if the count is already zero.

And here's my code
1
2
3
4
5
6
7
void CounterType::decreaseCount()
{
	if(count > 0)
		count--;
	else
		;
}


For me, line 5 and 6 seems strange.
I wonder if there is a better way to do so?
Get rid of those lines
1
2
3
4
5
void CounterType::decreaseCount()
{
	if(count > 0)
		count--;
}
If you really want to do something with the else, you can throw an exception or just do as @ats15 suggested and get rid of the else part
Thanks! I though one "if" must pair up with one "else"!
Topic archived. No new replies allowed.