I have the following code:
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&)’),这表明编译器对于非模板函数f()调用了operator pointer,但是却没有对于模板函数tf()进行调用。为什么会这样?是否有任何解决方法,而不需要重载tf()来创建一个const和non-const版本?
非常感谢您的帮助!