Nov 11, 2010 at 2:00pm UTC
Hi,
What makes the pow function?I could not understand.
Can you briefly explain?
Nov 11, 2010 at 2:11pm UTC
1 2 3 4
double pow(
double x,
double y
);
=> x
y
Last edited on Nov 11, 2010 at 2:22pm UTC
Nov 11, 2010 at 2:15pm UTC
an exponentiation function.I got it thanks.
I am now
mypow(double, index); I am writing
Find a way to have 2 ** I call mypow(2 ,I);
Define a class I n d e x to hold the index for an exponentiation function
How do I do this operation.?
Last edited on Nov 11, 2010 at 2:19pm UTC
Nov 11, 2010 at 9:04pm UTC
I guess you could overload the dereference operator for your Index class so that it returns something of type, let's say, Rdy2Pow. Then, you can overload double operator *(double x, Rdy2Pow y)
to return mypow(x,y)
.
Though, I know people who would rather eat dead mice than write something like this...
Nov 11, 2010 at 10:23pm UTC
@m4ster r0shi:
you would rather eat live mice?
Nov 11, 2010 at 11:13pm UTC
The question of the creator of C + +. (Bjarne Stroustrup)
Nov 12, 2010 at 11:52pm UTC
still could not figure out this problem
Nov 13, 2010 at 4:32pm UTC
What is it that you don't understand?
This -> cout << 2**e << endl;
calls *e
(i.e. e.operator *()
) first.
That returns a temporary Rdy2Pow object, I'll call it r2p.
Now, we have something that looks like cout << 2*r2p << endl;
.
Next, 2*r2p
(i.e. operator *(2.0,r2p)
) is called and returns pow(2.0,0.5)
, which is the square root of 2.
Finally, we have 1.4142... printed in the console window.
Nov 13, 2010 at 6:42pm UTC
I understand very well.thanks