D
Daniel
So why does the following compile? (g++ and comeau)
struct F{
int i;
};
F f() { return F();}
void function() {
f()=F();
}
If I replace F with int (or return a pointer pointer), the compiler
gives the expected message that the return of f() is not an l-value.
But it compiles fine as above (just produces unexpected results). This
came up with a class which has operator[] which returns by value and
allowed c[10]=value; to compile, but have no actual effects. I guess
the right solution is to return a "F const" (in generic code, so it
works with pointers too) or a const &.
Should such compile? And why is a builtin type different from a struct
in this context? Thanks.
--Daniel
struct F{
int i;
};
F f() { return F();}
void function() {
f()=F();
}
If I replace F with int (or return a pointer pointer), the compiler
gives the expected message that the return of f() is not an l-value.
But it compiles fine as above (just produces unexpected results). This
came up with a class which has operator[] which returns by value and
allowed c[10]=value; to compile, but have no actual effects. I guess
the right solution is to return a "F const" (in generic code, so it
works with pointers too) or a const &.
Should such compile? And why is a builtin type different from a struct
in this context? Thanks.
--Daniel