【发布时间】:2010-04-19 17:39:42
【问题描述】:
我有以下代码:
template <class T>
struct pointer
{
operator pointer<const T>() const;
};
void f(pointer<const float>);
template <typename U>
void tf(pointer<const U>);
void g()
{
pointer<float> ptr;
f(ptr);
tf(ptr);
}
当我使用 gcc 4.3.3 编译代码时,我收到一条消息 (aaa.cc:17: error: no matching function for call to ‘tf(pointer<float>&)’),表明编译器为非模板函数 f() 调用了 'operator pointer<const T>',但没有为模板函数 tf( )。为什么以及是否有任何解决方法不使用 const 和非 const 版本重载 tf()?
提前感谢您的帮助。
【问题讨论】:
-
也许 stackoverflow 软件正在删除您的模板尖括号?