ショット C++ コード スニペットに関して短い質問があります。演算子を評価しようとするとすぐにコンパイル エラーが発生します()
(メイン メソッドで 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;
}
コンパイルエラーはドイツ語ですが、基本的には..
呼び出しのための一致があります」。