Ioannis Vranos http:/ /www.3.brinkster.com/noicys [...] 不,这是一个左值。是的,对于内置类型,您只能分配一个 左值。但由于DoubleInDisguise是一个用户定义的类型,它有一个成员 函数operator =(语义上,无论如何),可以在右值上调用。 为了防止这种混乱,你可以将Chocolate2更改为 DoubleInDisguise const Chocolate2(){...} Denis The following compiles:// syrup.cppstruct 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 anlvalue. But now, see my last line of code, take away the // commenters. Itwon''t compile. You can assign to a temporary, yet it can''t act as adouble&?! What the hell is going on?-JKop 解决方案The above takes a double as an argument while you are passing it aDoubleInDisguise.Regards,Ioannis Vranos http://www23.brinkster.com/noicys The above line does this: Chocolate2() returns a temporary DoubleInDisguise object which is then assigned the value of the temporary on the right (which is initialised to 0).The above is passing to the void Manipulate(DoubleInDisguise&) atemporary of type DoubleInDisguise which is not allowed since it isgetting a reference. The only way you can do it is by making the functioninline void Manipulate(const DoubleInDisguise& input){//input.data = 222.76;}that is with a const reference. I suggest you get and read TC++PL 3, youwill find much knowledge in this book.Regards,Ioannis Vranos http://www23.brinkster.com/noicys[...]No, it is an rvalue. Yes, for built-in types, you can only assign to anlvalue. But since DoubleInDisguise is a user-defined type, it has a memberfunction operator = (semantically, anyway), which can be called on an rvalue.To prevent this kind of confusion, you can change Chocolate2 toDoubleInDisguise const Chocolate2() {...}Denis 这篇关于左值左值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!