A
Alexander Dong Back Kim
Dear all,
I'm just wondering whether I can define a compile-time error for a
class
or a function when the parameters are wrong.
For example,
class Test
{
protected :
int _value;
int _max;
int _min;
public :
Test();
Test(int v, int max, int min);
};
Test::Test() : _value(0), _max(0), _min(0) { }
Test::Test(int v, int max, int min)
{
_value = v;
if (max < min || v > max || v < min)
{
// throwing an error
}
else
{
_value = v; _max = max; _min = min;
}
}
It would be really nice that if the "throwing an error" actually
causes
an compile-time error with nice error message something like
"ERROR : Test::Test(int v, int man, int min) assigned wrong
parameters"... but I have no idea how do this and I'm even not sure
whether this approach is allowed or not.
any suggestion or trick? =)
regards,
Alex Kim
I'm just wondering whether I can define a compile-time error for a
class
or a function when the parameters are wrong.
For example,
class Test
{
protected :
int _value;
int _max;
int _min;
public :
Test();
Test(int v, int max, int min);
};
Test::Test() : _value(0), _max(0), _min(0) { }
Test::Test(int v, int max, int min)
{
_value = v;
if (max < min || v > max || v < min)
{
// throwing an error
}
else
{
_value = v; _max = max; _min = min;
}
}
It would be really nice that if the "throwing an error" actually
causes
an compile-time error with nice error message something like
"ERROR : Test::Test(int v, int man, int min) assigned wrong
parameters"... but I have no idea how do this and I'm even not sure
whether this approach is allowed or not.
any suggestion or trick? =)
regards,
Alex Kim