C++面向对象程序设计 015:看上去好坑的运算符重载 ---- (北大Mooc)

文章目录


原题题目

在这里插入图片描述
在这里插入图片描述


代码实现

MyInt( int n) {
    
     nVal = n ;}
	operator int(){
    
    return nVal;}
    MyInt & operator-(int n)
    {
    
    
        nVal-=n;
        return *this;
    }
    friend ostream & operator <<(ostream & os,const MyInt & a)
    {
    
    
        os<<a.nVal;
        return os;
    }

猜你喜欢

转载自blog.csdn.net/qq_37500516/article/details/114837855