On 28-mar-10, at 15:03, so wrote:

One more thing about the code :

T inv(T m)() {
        return 1.0 / m;
}

What if we call inv(5)?
yes what about it what should the compiler do? read your mind? the code that I gave returns 0

This is an error, why?

- Function explicitly states that the parameter is a floating point type.

how?

- Operations between floating point types and integers result a floating point type

this is the case

, as you see from the return type, code returns the type of parameter, in this case an integer.

yes you can write a template that automatically "upconverts" to float, but I don't think that is the correct thing for a default thing to do, why do you alway want to have floats as result?

Thanks.

Reply via email to