Following is compiled OK in both gcc
and clang
:
class A{
public:
void operator++(){
printf("A++\n");
// return *this;
}
};
Doesn't "correct" way to implement this kind of operator be:
class A{
public:
A &operator++(){
printf("A++\n");
return *this;
}
};
Is void
version a hack? I never saw syntax like this. Google search returns only one educational IBM paper about it.
Why this is not wide used way to implement pre-increments against returning self reference.