C++ looks like a pit operator overloading

Total time limit: 
1000ms
Memory limit: 
65536kB
describe
program fill in the blanks
#include <iostream>
using namespace std;
class MyInt
{
	int nVal;
	public:
	MyInt( int n) { nVal = n ;}
// add your code here
};
int Inc(int n) {
	return n + 1;
}
int main() {
	int n;
	while(cin >>n) {
		MyInt objInt(n);
		objInt-2-1-3;
		cout << Inc(objInt);
		cout <<",";
		objInt-2-1;
		cout << Inc(objInt) << endl;
	}
	return 0;
}
Input multiple sets of data, one line per set, integer n output For each set of data, output one line, including two integers, n-5 and n-8 sample input
20
30
Sample output
15,12

25,22


#include <iostream>
using namespace std;
class MyInt
{
	int nVal;
	public:
	MyInt( int n) { nVal = n ;}

MyInt& operator -(int a){
        nVal-=a;
        return *this;
    }
    operator int () {
    return nVal;
    }
};
int Inc(int n) {
	return n + 1;
}
int main() {
	int n;
	while(cin >>n) {
		MyInt objInt(n);
		objInt-2-1-3;
		cout << Inc(objInt);
		cout <<",";
		objInt-2-1;
		cout << Inc(objInt) << endl;
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324649307&siteId=291194637