Answer to Question #256837 in C++ for xyz

Question #256837

WAP to increment member variables by 2 of objects using operator overloading

1
Expert's answer
2021-10-27T00:26:02-0400
#include<iostream>
using namespace std;
class Increment{
	private:
		int x;
	public:
		Increment(int i){
			x= i;
		}
		
		void operator ++(){
			x= x+2;
		}
		void display(){
			cout<<x<<endl;
		}
};


int main(){
	Increment in(9);
	in.display();
	++in;
	in.display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS