函数对象 的问题 帮忙看看
#pragma once
#include "stdafx.h"
#include<functional>
#include<algorithm>
using namespace std;
template<class T>
CString convert_char( const T& value)
{
CString strRet;
strRet.Format(_T("%d"), value);
return strRet;
}
template<class T> struct Convert : public unary_function<T, CString>
{
CString strRet;
public:
CString operator() (const T& value )
{
return strRet += convert_char<T>(value);
}
CString result()
{
return strRet;
}
};
template<class VL, class T>
void convert_array(VL it_begin, VL it_end, CString& strBuf)
{
Convert<T> Res;
for_each( it_begin, it_end, Res);
strBuf = Res.result();
}
然后测试的时候发现
CString str;
int a[10] = {0, 1, 2, 3, 4,5,6,7,8,9};
str = convert_array( &a[0], &a[10], str); ///这里str输出还是空的,各位大侠帮忙看看 谢谢
[解决办法]
sorry 忘了说明一下
代码改成下面的.