In my specific case, a custom iterator is used, but this question is general. I'm not sure how to write a return type for this postfix increment method:
template<typename T>
struct MyIterator {
size_t loc;
MyIterator operator++(int) {
MyIterator temp(*this);
++loc;
return temp;
}
};
This compiles, but also:
template<typename T>
struct MyIterator {
size_t loc;
MyIterator<T> operator++(int) {
MyIterator<T> temp(*this);
++loc;
return temp;
}
};
The other two configurations also work fine (i.e. placing <T>only in one of the instances MyIterator). Is there a “right” way to write this? Does it matter?
source
share