Dave's Brain

Browse - Programming Tips - How do I declare the pre and post increment operators?

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

Add a comment

Sign in to add a comment
Copyright © 2008-2017, 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.