Take following piece of code as an example:
template<class Derived>
struct base {
Derived operator++(int){
auto tmp = static_cast<Derived &>(*this);
++static_cast<Derived &>(*this);
return tmp;
}
};
struct der : public base<der> {
der &operator++(){
return *this;
}
};
int main(){
der d;
d++;/// <<< compilation error here
}
I get following error from compiler:
error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
Why isn't my postfix operator visible for compiler? Does it contain some kind of error or is it some unknown to me C++ feature? Can this code be fixed so that postfix operator++
will work as expected?