|
![](/i/fill.gif) |
Slime <fak### [at] email address> wrote:
> My point was, isn't "something_cast<int>()" the C++ way instead of "int()"?
Sometimes the latter cast is necessary.
Consider this:
template<typename Type1, typename Type2, typename TypeConverter>
void foo(Type1 v)
{
Type2 v2 = TypeConverter(v);
...
}
Now, 'TypeConverter' can be an inner type (eg. 'int'), an abstract
type (eg. a user-defined class), a function or a class instance (for
which the 'operator()' is defined).
For example, you could call the above function like this:
int convertDoubleToInt(double d)
{
return some_complex_conversion_from_d_to_int;
}
...
foo<double, int, convertDoubleToInt>(xyz);
In this case foo() makes a convertDoubleToInt() function call.
However, of you do it like this:
foo<double, int, int>(xyz);
what foo() will do is a cast (that is: "int v2 = int(v);").
Since specially in template functions a xyz() call can be many things
(function call, operator() call, typecast), that's the reason why the
'type(value)' casting is necessary.
--
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}// - Warp -
Post a reply to this message
|
![](/i/fill.gif) |