for_each调用类的有两个参数的静态函数

类b中有一个函数要用for_each进行一些操作,为了不单独写一个类或函数(仅b类使用)进行了以下试验,记录如下以防忘记

在gcc4.4下编译通过,VC6时类a需要提出来。

 

#include <functional>
#include <algorithm>

class b
{
public:
    class a
    {
    public:
        static bool test(int n, b* pb)
        {
            printf("%d/n", n+pb->m_1+pb->m_2);
            return true;
        }
    };
public:
    
    void mm()
    {
        m_1 = 100;
        m_2 = 1000;
        int arr[] = {0,1,2,3,4,5,6,7,8,9};
            
        std::for_each(arr, arr+10, std::bind2nd(std::ptr_fun(b::a::test), this));     

        //也许VC能过  

        //std::for_each(arr, arr+10, std::bind2nd(std::ptr_fun(b::a::test), this));
    }
private:
    int m_1;
    int m_2;
};

int main(int argc, char* argv[])
{
    b().mm();
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值