nameless objects

using namespace std;
#include <iostream>

class Sample
{
	//private data section
	private:
	int count;
	
	public:
	//default constructor
	Sample()
	{ count = 0;}      

	//parameterized constructor
	Sample(int c)
	{ count = c;}      

	//Operator overloading function definition
	Sample operator++()
	{ 
		++count;
		//returning count of Sample
		//There is no new object here, 
		//Sample(count): is a constructor by passing value of count
		//and returning the value (incremented value)
		return Sample(count);
	}
	
	//printing the value
	void printValue()
	{
		cout<<"Value of count : "<<count<<endl;
	}
};

//main program
int main()
{
	int i = 0;
	Sample S1(100), S2;

	for(i=0; i< 5; i++)
	{    
		S2 = ++S1;

		cout<<"S1 :"<<endl;
		S1.printValue();

		cout<<"S2 :"<<endl;
		S2.printValue();
	}
	return 0;    
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source