B
benben
I am a C++ guy recently migrated to C#. One of the thing I don't understand
is assignment (=) and equality (==) operators. If I try to do the following:
C a = new C;
C b = a;
Then I will get both a and b referring to the same object, which is not
exactly the copy constructor semantics in C++. But I can do the following to
remedy:
C c = new C(a);
But, what if I try to assign an object with another object? An assignment
operator only tries get the lvalue referring to the rvalue, so far I guess.
c = a; //now a, b and c are refering to the same object
Another situation I can get myself out is the use of equality operator (==).
So what does the semantic imply? Are they to answer "are the two references
referring to the same object?" or "are they equal by calling the overloaded
operator ==, if any?"
C d = new C;
C e = new C(d);
bool i = (d == e); //what do you say?
ben
is assignment (=) and equality (==) operators. If I try to do the following:
C a = new C;
C b = a;
Then I will get both a and b referring to the same object, which is not
exactly the copy constructor semantics in C++. But I can do the following to
remedy:
C c = new C(a);
But, what if I try to assign an object with another object? An assignment
operator only tries get the lvalue referring to the rvalue, so far I guess.
c = a; //now a, b and c are refering to the same object
Another situation I can get myself out is the use of equality operator (==).
So what does the semantic imply? Are they to answer "are the two references
referring to the same object?" or "are they equal by calling the overloaded
operator ==, if any?"
C d = new C;
C e = new C(d);
bool i = (d == e); //what do you say?
ben