我有一个关于拍摄 C++ 代码片段的简短问题。一旦我想评估()
运算符(在 main 方法中返回 0 之前的最后一行),我就会得到一个编译错误。代码如下所示:
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
//multiplication by 10
template <typename A, typename B>
struct multiply_by_ten : unary_function<A, B> {
B operator()(A& a) {
return a*10;
}
};
//addition of the paramters
template <typename A, typename B, typename C>
struct add: binary_function<A, B, C> {
C operator()(A& a, const B& b) {
return a + b;
}
};
template <typename BinOp, typename Op1, typename Op2>
class combineops_t : public unary_function<typename Op1::argument_type,typename BinOp::result_type>
{
protected:
BinOp o; Op1 o1; Op2 o2;
public:
combineops_t(BinOp binop, Op1 op1, Op2 op2) : o(binop), o1(op1), o2(op2) {}
typename BinOp::result_type operator()( const typename Op1::argument_type &x) {
return o(o1(x),o2(x));
}
};
int main(int argc, char **argv) {
add<int, int, int> a;
multiply_by_ten<int, int> b;
multiply_by_ten<int, int> c;
combineops_t<binary_function<int, int, int> , unary_function<int, int> , unary_function<int, int> >
z(a, b, c);
cout << z(13);
return 0;
}
编译错误是德语,但它基本上说..
现在可以调用"。