binary_function Structure Sample
사용 하는 방법을 보여 줍니다 있는 binary_function 구조에는 STL (표준 템플릿 라이브러리)에서 Visual C++.
template<class _A1, class _A2, class _R>
struct binary_function
{
typedef _A1 first_argument_type;
typedef _A2 second_argument_type;
typedef _R result_type;
};
설명
[!참고]
프로토타입에 클래스/매개 변수 이름은 헤더 파일에서 버전이 일치 하지 않습니다.일부 가독성을 높이기 위해 수정 되었습니다.
binary_function< A, B, C > 클래스 데이터 형식 A와 B 인수로 받아 데이터 형식 C 개체를 반환 하는 이진 연산자 함수를 쉽게 정의할 수 있도록 하는 기본 클래스로 사용 됩니다.
예제
// binfunc.cpp
// compile with: /EHsc
//
// Structure used: binary_function<A,B,C> - base
// class used to create operator
// functions taking data types A
// and B and returning data type C.
#include <functional>
#include <iostream>
using namespace std ;
class binary_test : public binary_function<binary_test &,int,float>
{
public:
float value;
binary_test(){value=10.0;}
binary_test(float x){value=x;}
result_type operator<<(second_argument_type arg2);
};
binary_test::result_type
binary_test::operator<<(binary_test::second_argument_type arg2)
{
value = (float)(((int)value) << arg2);
cout << "New value after shift is " << value << endl;
return value;
}
int main(void)
{
binary_test item;
cout << "Begin" << endl;
item = item << 2;
}
Output
Begin
New value after shift is 40
요구 사항
헤더: < 기능 >