0
点赞
收藏
分享

微信扫一扫

c++,函数调用运算符重载

勇敢的趙迦禾 2022-04-14 阅读 34
c++

#include <iostream>
#include<stdlib.h>
using namespace std;
#include <stdio.h>
#include<string>
class My
{
public:
    void operator()(string test)
    {
        cout<<test<<endl;
    }
};
class Myadd
{
public:
    int operator()(int num1,int num2)//匿名对象
    {
        return num1+num2;
    }
};
void test02()
{
    Myadd myadd;
    myadd(100,100);
    int ret=myadd(100,100);
    cout<<ret<<endl;
    cout<<Myadd()(100,100)<<endl;
}
void test01()
{
    My my;
    my("hello ");

}
int main()
{
    //test01();
    test02();


    system("pause");
    return 0;
}
 

举报

相关推荐

0 条评论