0
可以说,我正在写一个某种类型转换操作符的,我想用它这样:多参数模板函数和重载歧义错误
SomeType a;
AnotherType b = conv<AnotherType>(a);
首先,我写的底座(默认)功能:
template <typename T, typename U>
inline T conv(const U& a)
{
return T(a);
}
完全专业化(或非模板超载)是没有问题的,但是,当我想要做这样的事情:
template <typename T>
inline Point<T> conv(const Ipoint& p)
{
return Point<T>(p.x, p.y);
}
我不能写入从IPOINT由于歧义任何更多的转换函数(给FunkyPoint < T>例如),并且我结束了一个笨拙用法:
Ipoint a;
Point<double> b = conv<double>(a); //ugly!
//Point<double> b = conv<Point<double> >(a); //I want that, but it (obviously) does not compile.
有没有这样做的任何方式很好吗?
为什么不重写构造函数或转换操作符? – kennytm 2010-05-21 19:56:55
因为我无法访问上述结构(Ipoint/Point < T >)。 – maticus 2010-05-21 20:11:35