Posted on 2011-06-12 21:48
RTY 閱讀(488)
評論(0) 編輯 收藏 引用 所屬分類:
C/C++ 、
轉(zhuǎn)載隨筆
★參考資料★ http://www.ok2002.com/cc/cc/v.asp?r=a2273562198117 重載括號和函數(shù)指針//C++中重載括號和C語言中的函數(shù)指針實現(xiàn)同樣的功能
#include<iostream>
using namespace std;
int add(int a,int b)
{
return a+b;
}
class class1
{
public:
int operator()(int x,int y)//重載操作符
{
return x+y;
}
};
void main()
{
int (*p)(int,int)=add;//函數(shù)指針
cout<<p(5,3)<<endl;
class1 add;
cout<<add(5,3)<<endl;
}
/*--
8
8
Press any key to continue
--*/