S
Silver
Hi everyone,
I want to overload the ! operator, so that when I write this in main
x!
I can get the factorial of x.
The problem is, that the operator I want to overload takes no parameter.
Most examples I'ver seen, have a parameter. I wonder if this causes the
problem.
My code is
float A:perator !()
{
float product = 0.0;
if (n != 0)
{
for ( ; n > 0 ; n--) // We omit the initialization expression
product *= n; // since we have initialized n with the constuctor
return product;
}
else
return 1.0;
}
I want to overload the ! operator, so that when I write this in main
x!
I can get the factorial of x.
The problem is, that the operator I want to overload takes no parameter.
Most examples I'ver seen, have a parameter. I wonder if this causes the
problem.
My code is
float A:perator !()
{
float product = 0.0;
if (n != 0)
{
for ( ; n > 0 ; n--) // We omit the initialization expression
product *= n; // since we have initialized n with the constuctor
return product;
}
else
return 1.0;
}