给定以下代码:
#include <vector>
template<class C1, class C2, class Op>
std::vector<typename Op::result_type>
f(Op op, const C1& src1, const C2& src2)
{
}
template<class It, class Op>
std::vector<typename Op::result_type> g(Op op, It begin, It end)
{
}
template<class It1, class It2, class Op>
std::vector<typename Op::result_type> g(Op op, It1 left_begin, It1 left_end, It2 right_begin)
{
return std::vector<typename Op::result_type>();
}
struct ToS
{
typedef double result_type;
double operator() (long , double ) const { return 0.0; }
};
std::vector<double> h(std::vector<long> const& vl, std::vector<double> const& vd)
{
return g(ToS(), vl.begin(), vl.end(), vd.begin());
}
使用 Visual C++ 2010 (SP1) 编译时,出现以下错误:
1>VC10Error.cpp(30): error C2893: Failed to specialize function template 'std::vector<Op::result_type> g(Op,It1,It1,It2)'
1> With the following template arguments:
1> 'std::_Vector_const_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<long,std::allocator<long>>
1> ]
1> 'std::_Vector_const_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<double,std::allocator<double>>
1> ]
1> 'ToS'
1>VC10Error.cpp(30): error C2780: 'std::vector<Op::result_type> g(Op,It,It)' : expects 3 arguments - 4 provided
1> VC10Error.cpp(12) : see declaration of 'g'
我不明白他们。首先,当然,错误信息基本上
总结为“这里有问题,但我们不会告诉你什么”。
其次,我没有发现任何问题; g++(版本 4.4.2)也没有。
其他有趣的症状:如果你在后面添加 using std::vector;
包含并删除所有 std::
,它可以工作——我会的
认为那应该没有效果。如果你删除任何一个
函数 f
(实际上没有在任何地方使用)或第一个版本
函数g
,也可以。
我是不是疯了,还是 VC10 真的还没有投入生产?
编辑:只是补充一点:如果它是编译器中的错误,我如何可靠地解决它?
最佳答案
确实在编译器中出现了一个错误。
在您的简化示例中,如果 g()
的两个版本,问题就会消失。交换位置,或者如果 f()
被注释掉,或 f()
与 g<It,Op>(Op, It, It)
交换名额.
关于c++ - 这是 Visual C++ 2010 中的错误,还是我遗漏了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5989534/