나는 0으로 내 인쇄 펑의 첫 번째 인수를 결합하고 싶습니다 :는
이#include<iostream>
#include<functional>
using namespace std;
class Print : public std::binary_function<int,int,void>{
public:
void operator()(int val1, int val2)
{
cout << val1 + val2 << endl;
}
};
int main()
{
Print print;
binder1st(print,0) f; //this is line 16
f(3); //should print 3
}
위의 프로그램 (C++ Primer Plus에서 예를 기반으로)가 컴파일되지 않습니다 :
line16 : error : missing template arguments before ‘(’ token
무엇이 잘못 되었나요?
저는 C++ 11 및 부스트 기능을 사용하고 싶지 않습니다.
편집이 : 운영자() 반환 형식이 단순
당신은'bind1st (print, 0) (3);'을 사용할 수 있으며, 템플릿 인자를 직접 지정할 필요가 없습니다. – Simple
왜 bind1st 대신 bind1st (템플릿 args를 추론 할 수 있습니까?) – doctorlove
@doctorlove : print (int, int)를 f (int)로 변환 한 다음 f를 여러 번 사용하기 때문에. bind1st로 가능합니까? – cpp