#include <iostream>

class Test;

typedef void (Test::*Fn)(void);

class Test
{

public:

    explicit Test()
    {
        m_num = 0;
        m_fn[0] = &Test::Oper1;
        m_fn[1] = &Test::Oper2;
    }

    ~Test()
    {

    }

    void Show(int i)
    {
        if ( i > 2 )
        {
            (*this.*m_fn[0])();
        }
        else
        {
            (*this.*m_fn[1])();
        }
    }

    void Oper1(void)
    {
        m_num += 10;
        std::cout << "void Oper1(), age: " <<m_num << std::endl; 
    }

    void Oper2(void)
    {
        m_num += 20;
        std::cout << "void Oper2(), age: " <<m_num << std::endl;
    }
private:
    Fn m_fn[2];
    int m_num;
};

int main()
{
    Test obj;
    while (1)
    {
        int i;
        std::cin >> i;
        obj.Show(i);
    }
    return 0;
}

 

posted on 2013-06-07 02:26  cqfuture  阅读(1111)  评论(0编辑  收藏  举报