---
title: "An Example of Using std::tr1::bind"
author: "standalone"
date: "2014-03-10T16:49:28Z"
tags: []
categories: ["编程语言"]
slug: "an-example-of-using-std-tr1-bind"
draft: false
lastmod: "2014-03-10T16:49:28Z"
id: 2028983
url: "https://standalone.iteye.com/blog/2028983"
---

```c++

#include <iostream>
#include <tr1/functional> 
using std::tr1::bind;
using std::tr1::function;
using std::tr1::placeholders::_1;
using std::tr1::placeholders::_2;

class CTest
{
        public:
                int test( int a, int b , int c, int d)
                {   
                        return a - b + c*d;
                }   
};
int main()
{
   CTest obj;
   std::tr1::function<int(int, int)> func = bind<int>(&CTest::test, &obj, 3, 3 , _1, _2);
   int c = func(3,4);
   std::cout<< c << std::endl;
   return 0;
}

```