运算符重叠 [英] operator overloding

查看:73
本文介绍了运算符重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< iostream>
使用名称空间std;


类INTEGER
{
公开:
    int * ref;

    int num_1;
    int num_2;
    int num_3;

   



INTEGER运算符+(INTEGER sref)
    {
       如果(num_1 == num_2)
        {
   

           
            =((* this).ref + sref.ref);
        }

       

       否则,如果(num_1!= num_2)
        {
            cout<<更改值"<< endl;
       
        }
     }

    };


    void main()
    {
整数num_1(1);
整数num_2(1);
整数num_3;




num_3 = num_1 + num_2;
cout<< num_3.ref;
cin.get();
    }

       
请zzzz帮我解决它的错误..:(

#include<iostream>
using namespace std;


class INTEGER
{
public:
    int *ref;

    int num_1;
    int num_2;
    int num_3;

   



INTEGER operator+(INTEGER sref)
    {
        if (num_1==num_2)
        {
   

           
            =((*this).ref + sref.ref);
        }

       

        else if (num_1 != num_2)
        {
            cout<<"change the value"<<endl;
       
        }
     }

    };


    void main()
    {
INTEGER  num_1(1);
INTEGER  num_2(1);
INTEGER  num_3;




num_3=num_1+num_2;
cout<<num_3.ref;
cin.get();
    }

       
plzz help me out with its errors..:(

推荐答案

Hello,

 

谢谢您的发帖!  ;我建议将您的问题发布到MS论坛之一中,

Windows开发人员中心 > Windows窗体论坛 > Windows窗体常规
Windows Developer Center > Windows Forms Forums > Windows Forms General


这篇关于运算符重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆