C++ Object-Oriented Programming 015: Operator overloading that looks good-(Beijing University Mooc)

Article Directory


Original title

Insert picture description here
Insert picture description here


Code

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;
    }

Guess you like

Origin blog.csdn.net/qq_37500516/article/details/114837855