Dave's Brain

Browse - programming tips - c++ pre post increment operator

Date: 2011apr29
Language: C++

Q.  How do I declare the pre and post increment operators?

A.  The post increment has a parameter of int and pre is has no parameters.
For example:

class MyClass
{
	int		i;

public:

	void operator++() // PRE-increment
	{
		++i;
	}

	void operator++(const int) // POST-increment
	{
		i++;
	}

};
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: