|
toxcct wrote: can't you just answer when we need more informations about what you're trying to do ?
IMHO lately he is just trying to exasperate the good old C++ compiler.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: he is just trying to exasperate the good old C++ compiler
well, i feel like a good old C++ compiler then... hey ! not that old BTW ! lol.
BTW, is it you who gave me '3' ?
i should have known that i was about to get an answer from G_G
|
|
|
|
|
Hi toxcct,
Please makes your hands dirty with this sample. It is not very hard. My thoughts are,
f (X().operator=(X()));
the copy assignment operator is invoked, and this can handle an rvalue as its argument. Then, it returns a reference, so f() can handle the reference as it is an lvalue.
It is appreciated if you could comment and correct me if I am wrong.
regards,
George
|
|
|
|
|
your thoughts are correct about the operator=().
however, it's perfectly not clean to write such a code...
and last, f(X()) will get the reference returned by the X::X() constructor and make it its parameter...
George_George wrote: It is appreciated if you could comment and correct me if I am wrong
it is appreciated if you could (for one time !) answer about questions which don't necessarily belong to the initial topic...
Off Topic Now:
Do you understand when we tell you to stop voting posts ?
Do you understand why we're upset about your questions (as interresting as they can be though) ?
Do you understand why you will never be a friend of mine if you don't just change your way of acting in this forum ?
modified on Monday, December 17, 2007 9:54:47 AM
|
|
|
|
|
I should have known you wouldn't ever dare replying to my post. idiot you are !
modified on Monday, December 17, 2007 11:51:40 AM
|
|
|
|
|
toxcct wrote: SOAB you are !
Why so harsh? It doesn't paint you in a very good light, no matter how you feel about someone.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
me rude ? see how this guy's asking his sh*t again and again, but a simple question we can ask him and there's nobody anymore.
he's getting on the nerves of many of us here, and yes, i'm personnaly very disapointed of that dork
|
|
|
|
|
Never let yesterday use up too much of today.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Thanks ted,
I agree. If his post has values, I will try my best. I will rate him 5 as a X'Mas gift.
regards,
George
|
|
|
|
|
Actually he already is a CP MVP.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
toxcct wrote: not that old BTW ! lol.
Of course, it was just a friendly epithet.
toxcct wrote: BTW, is it you who gave me '3' ?
I never gave you such a high score!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi CPallini,
I am using Visual Studio 2008, not old compiler. Have you tried to compile the code with disabling language extension setting?
regards,
George
|
|
|
|
|
it was a joke, and it was for me !
why on hell did you vote him 3 for this ?
also, there's no need to repeat 3 times to deactivate that bloody language extensions. you already told it twice, that's more than enough. now sit and wait !
|
|
|
|
|
|
Hi toxcct,
I use this code to show and learn how compiler works internally to deal with lvalue and rvalue, and there is something unknown to us.
Have you tried my code (disable language extension please)? If you tried, I think you will be surprised to see why f (X() = X()) can compile, but f (X()) can not compile.
regards,
George
|
|
|
|
|
i have no compiler with me at work, but i'm absolutely certain that f(X()) compiles if the f() function is designed correctly (getting a copy or a reference).
|
|
|
|
|
I don't know the reason, but passing an assigment as a parameter... Well, in my opinion is not very elegant. And still more... you are making X() = X() like saying 1 = 1, I don't know why your code compile and pallini's not... but at least in my limited knowledge... that has no sense.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi Nelek,
Could you try to compile the simple code when diable language extension please? You will be surprised why f(X() = X()) can compile but f (X()) can not. Any ideas or insights to share are appreciated.
regards,
George
|
|
|
|
|
are you from China ?
modified on Monday, August 18, 2008 11:21 AM
|
|
|
|
|
Poor chinese people
Offtopic added:
About your questions above... I think the answers are quite easy... No, No, No and he doesn't care about.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
modified on Monday, December 17, 2007 9:58:04 AM
|
|
|
|
|
George_George wrote: Could you try to compile the simple code when diable language extension please? You will be surprised why f(X() = X()) can compile but f (X()) can not.
I don't have to do it.
Firstly... I use VC++ 6.0 (as I said in many other messages) so this is out of scope for me.
Then... I don't need to do it because I trust on what you say, I mean, if you say it compiles, why should I don't believe you? (Actually, sometimes you should do the same about the answers you get and don't ask 4 extra times to get an asnwer that you actually already got. It seems that you don't trust on the people who answers you, so... If you don't trust them... why to ask?)
George_George wrote: Any ideas or insights to share are appreciated
If you had payed attention to the text inside the answer...
Nelek wrote: I don't know the reason,... (other text)... I don't know why your code compile and pallini's not
I have already said it. The theory of this question is too deep for me. My knowledge is limited, but not my common sense.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
AFAIK, f(X()) doesn't compile because X() doesn't exist long enough (or is optimised away) to be passsed by reference (the X& reference requires a X instance to be initialized) into f(X& x) . f(X() = X()) works because two temporary objects are created; the assignment operator is fired, and a reference to the lhs temporary object is passed into f(X() = X()) .
IMHO, this code only demonstrates temporary objects and has no practical usage. It is like creating two trucks; cloning the features of one truck into the other, using the cloned truck for a bit, and destroying both trucks when done with the cloned one.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Monday, December 17, 2007 12:32:25 PM
|
|
|
|
|
Thanks George,
I think my original code breaks the C++ rule that non-const reference can not binded to a rvalue (in my case, X() will generate a temporary object instance, which is a rvalue). How do you think of it?
regards,
George
|
|
|
|
|
C++ creates temporary objects in many situations. However, you should avoid such situations whenever possible. Your code only is really inefficient due to that fact, and most C++ programmers won't touch such code with a ten-foot pole. Also, a reference requires initialization; otherwise, the compiler will emit an error.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|