|
Hey man, what are you trying to do with the following statement?
George_George wrote: f (X() = X());
f(X());
isn't enough for you?
BTW
You're passing a reference to a temporary object to function f .
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.
|
|
|
|
|
Thanks CPallini,
Why you change my code from f(X() = X()) to f (X())? Are they the same? Could you try to compile my code please?
If you change my code to f (X()), the code can not compile. But my code can compile, why? It is a question to you.
regards,
George
|
|
|
|
|
The code compiles (as it should do) in both cases. I've already made a test.
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,
Could you disable the language extension and have a try please?
regards,
George
|
|
|
|
|
I've done and indeed only your dirty trick compiles. Probably (I have no certainties at this point) you're stressing a dark corner of the C++ standard: the assignment operator breaks the r-value nature of X() .
And IMHO it is weird since you cannot do that on built-in types.
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.
|
|
|
|
|
George_George wrote: Why you change my code from f(X() = X()) to f (X())?
because he asked a question.
Do you have a problem with questions ?
Do you fear that simple '?' character ?
can't you just answer when we need more informations about what you're trying to do ?
George_George wrote: It is a question to you
lammer
writing f(X() = X()) just has no sense. so re-read CPallini's question again, and reply to him.
George_George wrote: If you change my code to f (X()), the code can not compile
WTF have you ever written ? that's impossible and makes merfect sense to pass a brand new object as a function parameter.
Thanks to answer.
|
|
|
|
|
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
|
|
|
|