no 'operator++(int)' error

no 'operator++(int)' error
0.0 0



I have an enum and like to increments its value

typedef enum

GameObjectType m_gameObject;

When I do m_gameObject++ I get the following error on my console

error: no ‘operator**’ declared for postfix ’**’ [-fpermissive]

please help.



Please show line that causes error.


It’s whenever I call this code

m_gameObject ++;

Does NDK forbids incremental of enum type? It works fine on iOS


Incrementing the enum does not work for the following reasons.

Your enum type is a new Type for the compiler, this type has no definition for the post increment operator (that is the root cause of the error)
I do not know what iOS does here (do you comile this statement as C*+ code in iOS but there is a reason why there is no operator for that: enum values do not have to be contiguous.
Consider the following enum
enum MyEnum {
FirstValue, // = 0
SecondValue, // = 1
ThirdValue = 3
Know what should happen if you increment SecondValue? Should the new value be 2 ? Should it be set to ThirdValue? The same goes for incrementing ThirdValue. Is the new value set to 4 or should we wrap around?
Another interesting enum may be this:
enum MyEnum {
FirstValue = 1,
SecondValue = 1,
ThirdValue // = 2
Now what should happen if we increment FirstValue?
To solve your issue, first check your design, do you really need the increment operator for your enum type? If you do, you can implement the*+ operator for your enum type.
Within this operator you should include bounds checking and jump over any gaps that are within the enum constants. And you must not modify the enum value without modifying the operator function. If you add gapps or a new element you probably need to modify the function. (This is the main reason why you should think if you really need the increment operator.
If you don’t care on bounds checking and if your enum type is contiguous something like the following should work.

// prefix++
GameObjectType& operator++(GameObjectType& type) {
  return type = static_cast( ++static_cast(type) );

// postfix++
GameObjectType operator++(GameObjectType& type, int) {
  GameObjectType tmp(type);
  return tmp;