C++函数调用运算符重载
#include<iostream> #include<string> using namespace std; class MyPrint { public: void operator()(string text) { cout << text << endl; } }; class MyAdd { public: int operator()(int n1, int n2) { return n1 + n2; } }; int main() { MyPrint mp; mp("hello c++");//仿函数 cout << MyAdd()(100, 100) << endl; system("pause"); return 0; }
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号