AKever

导航

operator() 的使用

operator() 的使用

=========================

operator()是函数调用操作符!
STL中的各种functor就是重载它实现的.

举例(1):

class test
{
    void operator()(int x)
    {
        cout<<x<<endl;
    }
}
int main()
{
    test t;
    t(10);
    return 0;
}

举例(2):

using namespace std;

class Function
{
public:
    double operator()(double x) 
    {  
        return 2*x;
    } 
};

int main()
{
    Function myFunc;
    cout<<myFunc(1.0)<<endl;

    system("pause");
}

 

 

---- THE END

 

posted on 2015-07-01 11:26  AKever  阅读(979)  评论(0)    收藏  举报