C++ 模板函数专用化默认参数
问题也解决了 现在如果我这样使用它:function1,2,3;或者function1.0,这样看来,如果模板函数是专门化的,那么调用它时必须重写默认参数 但在我的第二个例子中,我替换了std::numeric_limits:。。与T。。调用function1时没有语法错误,为什么 我正在使用VisualStudio2010x64C++ 模板函数专用化默认参数,c++,visual-c++,templates,specialization,visual-c++-2010,C++,Visual C++,Templates,Specialization,Visual C++ 2010,问题也解决了 现在如果我这样使用它:function1,2,3;或者function1.0,这样看来,如果模板函数是专门化的,那么调用它时必须重写默认参数 但在我的第二个例子中,我替换了std::numeric_limits:。。与T。。调用function1时没有语法错误,为什么 我正在使用VisualStudio2010x64 由于最初的问题是因为bug,现在的问题变成了如何解决它?代码没有问题;COMWONE,英特尔C++ 11.1,G+4.1.2编译成功。 我猜这是编译器中的一个bug。
由于最初的问题是因为bug,现在的问题变成了如何解决它?代码没有问题;COMWONE,英特尔C++ 11.1,G+4.1.2编译成功。 我猜这是编译器中的一个bug。我最近提交了一个相关的,但与Visual C++ 2010编译器略有不同。 作为一种解决方法,您可以将呼叫打包:
template <typename T> void function(T arg1,
T min = T(0),
T max = T(1))
{
}
template <> void function<int>(int arg1, int min,int max)
{
}
有趣的是,如果类模板位于全局名称空间中,还有另一个问题。给定以下代码:
error C2589: '::' : illegal token on right side of '::'
error C2059: syntax error : '::'
两个实例都是格式良好的C++程序,
编译成功。 在里面 Comeau Online、Compiler和G++。
如和中所述,这是由于windows标头中定义了最小和最大宏。以下代码应通过阻止宏扩展来工作:error C2064: term does not evaluate to a function taking 0 arguments
如何向microsoft报告此错误?@uray:您可以通过我列出的错误报告链接在connect.microsoft.com上提交此错误;您必须登录并打开一个新缺陷。如果您不想,我将尝试将此问题和我之前报告的问题减少到一个常见示例中,然后重新提交该问题。让我知道;我很乐意帮忙。臭虫报告在
namespace N
{
template <typename T>
struct S
{
static T g() { return T(); }
};
}
template <typename T> void f(T = N::S<T>::g()) { }
template <> void f<>(int) { }
int main()
{
f<int>();
}
error C2589: '::' : illegal token on right side of '::'
error C2059: syntax error : '::'
template <typename T>
struct S
{
static T g() { return T(); }
};
template <typename T> void f(T = ::S<T>::g()) { }
template <> void f<>(int) { }
int main()
{
f<int>();
}
error C2064: term does not evaluate to a function taking 0 arguments
template <typename T> void function(T arg1,
T min = (std::numeric_limits<T>::min)(),
T max = (std::numeric_limits<T>::max)())
{
}
template <> void function<int>(int arg1, int min,int max)
{
}
int main(int argc,char* argv[])
{
function<int>(1);
}