L
lallous
Hello,
I would like to define a template as:
template <class T, class R> void func(T &r)
{
r = (T)((R)r);
}
For example:
double d;
func<double, int>(d);
this would do: (double)((int)d)
1)Is this a good way to achieve this?
I don't want to use any instance of "R" but just use it to cast.
2)
How can I set that "R" is by default a "long" type?
It seems that <class T, class R = long> will only work w/ classes and not
function templates.
Regards,
Elias
I would like to define a template as:
template <class T, class R> void func(T &r)
{
r = (T)((R)r);
}
For example:
double d;
func<double, int>(d);
this would do: (double)((int)d)
1)Is this a good way to achieve this?
I don't want to use any instance of "R" but just use it to cast.
2)
How can I set that "R" is by default a "long" type?
It seems that <class T, class R = long> will only work w/ classes and not
function templates.
Regards,
Elias