给出以下代码:
#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());
}
Run Code Online (Sandbox Code Playgroud)
使用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'
Run Code Online (Sandbox Code Playgroud)
我不明白他们.首先,当然,错误信息基本上总结为"这里有什么不对,但我们不会告诉你什么'.其次,我没有发现任何错误; g ++(版本4.4.2)也没有."其他有趣的症状:如果你using std::vector;
在include之后添加一个,并删除所有的std::
,它的工作 - 我会认为这应该没有效果.如果你删除该功能f
(真的没有在任何地方使用)或第一个功能版本g
,它也有效.
我疯了,还是VC10还没准备好生产?
编辑:只是补充:如果它是编译器中的错误,我该如何可靠地解决它?