I'd have to ask why are you using exceptions like this?
Exception handling adds quite a lot of overhead to the application. In this case you could just use if-else statements.
Anyways, you need to re-order your logic slightly otherwise both checks get done and you get duplicate outputs.
#include<iostream>
usingnamespace std;
void F(constint N) {
constint MAX = 100;
constint MIN = 50;
try {
if (N > MIN && N < MAX) {
cout << "N is ok at " << N << endl;
} elsethrow N;
} catch (constint ex) {
if (ex < MIN)
cout << "N is below MIN at " << N << endl;
else
cout << "N is above MAX at " << N << endl;
}
}
int main () {
F(75);
F(101);
F(40);
return 0;
}
Well, for one, you're trying to manipulate the value of size- which is not only just a value passed to the constructor, then to SetSize, but also a constant. So... you can't actually manipulate the value, for both reasons (why would you manipulate the value of a passed variable, anyway?). Do you have size initialized anywhere else in the code?