C++ 无法推断模板参数/没有';n';重载可以转换所有参数类型

C++ 无法推断模板参数/没有';n';重载可以转换所有参数类型,c++,templates,C++,Templates,我正试图编译一个由Jan Bartipan编写的名为vmath的向量库 有几个函数扩展向量的std命名空间,如下所示: #define VEC3 Vector3 namespace std { //... template <typename T> VEC3<T> min(const VEC3<T>& a, const VEC3<T>& b) { return VEC3<T&

我正试图编译一个由Jan Bartipan编写的名为vmath的向量库

有几个函数扩展向量的
std
命名空间,如下所示:

#define VEC3 Vector3

namespace std
{
    //...

    template <typename T>
    VEC3<T> min(const VEC3<T>& a, const VEC3<T>& b)
    {
        return VEC3<T>(::std::min(a.x, b.x), ::std::min(a.y, b.y), ::std::min(a.z, b.z));
    }

    //...
}
我在网上查看了一下,发现对
std::min
的调用可能需要模板化。因此,我尝试将代码更改为以下内容:

template <typename T>
VEC3<T> min(const VEC3<T>& a, const VEC3<T>& b)
{
    return VEC3<T>(::std::min<T>(a.x, b.x), ::std::min<T>(a.y, b.y), ::std::min<T>(a.z, b.z));
}
我希望你们都能对我做错了什么有所了解

谢谢


编辑:我正在使用Visual Studio 2013编译,因为在声明
std::min
的地方没有包含
,所以您对
std::min(const VEC3&,const VEC3&)的定义只会看到它自己

因此
std::min(a.x,b.x)
尝试匹配唯一可能的重载
std::min(const-VEC3&,const-VEC3&)
,而不能作为
a.x
double


#include
应该可以解决您的问题。

您是否包含定义了
std::min
?我下载了vmath,使用VC 2012,似乎可以编译。根据错误信息,我感觉答案可能是您如何使用新的min函数。我创建了两个Vector3和第三个Vector3来接收min的返回。没有编译器问题。@immibis没有,我没有包括它。包括它解决了这个问题。如果你写一个答案,我可以接受。向
std
添加重载会导致未定义的行为。
template <typename T>
VEC3<T> min(const VEC3<T>& a, const VEC3<T>& b)
{
    return VEC3<T>(::std::min<T>(a.x, b.x), ::std::min<T>(a.y, b.y), ::std::min<T>(a.z, b.z));
}
error C2665: 'std::min' : none of the 3 overloads could convert all the argument types