您的位置:首页 > 其它

一种构造组合方法以及bind的一种用法

2008-07-17 15:07 134 查看
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <algorithm>
#include <functional>
#include <string>
#include <iterator>

class base
{
public:
virtual void report(void)
{
std::cout<<"this is base"<<std::endl;
}
virtual ~base()
{}
protected:
private:
};

class sub:public base
{
public:
virtual void report(void)
{
std::cout<<"this is sub"<<std::endl;
}
protected:
private:
};

void print(int value)
{
int mod = 0;
int count = 0;
do
{
mod = value % 10;
value = value / 10;
count++;
std::cout<<mod<<std::endl;
} while(value > 0);

std::cout<<count<<std::endl;
}

void get_next(int init_seq[],int n,int length)
{
int j = -1;
bool is_over = true;
int count = 0;
do
{
std::copy(init_seq,init_seq+n,std::ostream_iterator<int>(std::cout));
count++;
is_over = true;
j = -1;
std::cout<<std::endl;

//get max j
for(int i=0; i<n; i++)
{
if(init_seq[i] < length-n+1+i)
{
j = i;
}
}
if (j>=0 && j<=n-1)
{
is_over = false;
init_seq[j]++;
for(int k=j+1; k<n; k++)
{
init_seq[k] = init_seq[k-1]+1;
}
}
} while(!is_over);
//std::copy(init_seq,init_seq+n,std::ostream_iterator<int>(std::cout));
//count++;
std::cout<<count<<std::endl;
}

const int select_length = 7;
//1......9不包括0
const int all_length = 9;
int main(void)
{
boost::bind(&base::report,_1)(new base());
boost::bind(&base::report,_1)(new sub);
//print(123456);

int seq[select_length];
for(int i=0; i<select_length; i++)
{
seq[i] = i + 1;
}
get_next(seq,select_length,all_length);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: