美文网首页
51 - More on Operator Overloadin

51 - More on Operator Overloadin

作者: 社交帐号直接注册 | 来源:发表于2018-01-02 21:32 被阅读0次
    #include <iostream>
    #include "Sally.h"
    using namespace std;
    
    int main()
    {
        Sally a(34);
        Sally b(21);
        Sally c;
    
        c = a+b;
        cout << c.num << endl;
        system("pause");
    }
    
    #include "Sally.h"
    #include <iostream>
    using namespace std;
    
    Sally::Sally()
    {
    }
    
    Sally::Sally(int a)
    {
        num = a;
    }
    
    Sally Sally::operator+(Sally aso)
    {
        Sally brandNew;
        brandNew.num = num + aso.num;
        return(brandNew);
    }
    
    #ifndef Sally_H
    #define Sally_H
    
    class Sally
    {
    public:
        int num;
        Sally();
        Sally(int);
        Sally operator+(Sally);
    };
    
    #endif // Sally_H
    

    相关文章

      网友评论

          本文标题:51 - More on Operator Overloadin

          本文链接:https://www.haomeiwen.com/subject/cyaqnxtx.html