D
Denis Remezov
JKop said:The following compiles:
// syrup.cpp
struct DoubleInDisguise
{
double data;
};
double Chocolate1()
{
double blah = 67.22;
return blah;
}
DoubleInDisguise Chocolate2()
{
DoubleInDisguise blah = { 67.22 };
return blah;
}
/*
inline void Manipulate(double& input)
{
input = 222.76;
}
*/
inline void Manipulate(DoubleInDisguise& input)
{
//input.data = 222.76;
}
int main()
{
//Manipulate( Chocolate1() );
Chocolate2() = DoubleInDisguise();
// Manipulate( Chocolate2() );
}
See how the return-value from Chocolate2() can have an assigment done to it.
This suggests that its non-const first of all, and secondly that it's an
lvalue.
[...]
No, it is an rvalue. Yes, for built-in types, you can only assign to an
lvalue. But since DoubleInDisguise is a user-defined type, it has a member
function operator = (semantically, anyway), which can be called on an rvalue.
To prevent this kind of confusion, you can change Chocolate2 to
DoubleInDisguise const Chocolate2() {...}
Denis