E
Ed
Hi, guys,
I met a issue that compiler can not deduce the template argument type
from my code.
template <typename Precision = float>
struct Vector
{
typedef Precision scalar;
Precision x;
Vector(): x()
{
};
Vector(Precision r)
{
x = r;
}
template <typename P>
Vector(Vector<P>& r)
{
x = (Precision) r.x;
}
template<typename P>
operator P()
{
return (P)x;
};
};
template <typename P>
void Hello(Vector<P> v)
{
};
// use of the template
int main()
{
Hello(1.0f); //Not work
float f;
Hello(f); //Not work
return 0;
}
I want compiler to understand Hello(1.0f) is
Hello( Vector<float>(1.0f) ).
But compiler can't find this.
Hoe can I make implicit constructor of Vector when the argument is
float?
Thanks!
I met a issue that compiler can not deduce the template argument type
from my code.
template <typename Precision = float>
struct Vector
{
typedef Precision scalar;
Precision x;
Vector(): x()
{
};
Vector(Precision r)
{
x = r;
}
template <typename P>
Vector(Vector<P>& r)
{
x = (Precision) r.x;
}
template<typename P>
operator P()
{
return (P)x;
};
};
template <typename P>
void Hello(Vector<P> v)
{
};
// use of the template
int main()
{
Hello(1.0f); //Not work
float f;
Hello(f); //Not work
return 0;
}
I want compiler to understand Hello(1.0f) is
Hello( Vector<float>(1.0f) ).
But compiler can't find this.
Hoe can I make implicit constructor of Vector when the argument is
float?
Thanks!