3 ms·
My guess is that the parent poster meant something more like: it's hard to tell whether A=B will deep copy, shallow copy or move the right hand side and which o
by dthul 5y ago
My guess is that the parent poster meant something more like: it's hard to tell whether A=B will deep copy, shallow copy or move the right hand side and which operator=() will actually be called.
First you need to figure out the types of A and B and their "modifiers" (like const or references) to start figuring out which operator=() could potentially be called. That might still be very hard to do if for example there are implicit conversions from B to some other type involved. Such conversions can depend on code which might be nowhere close to where the operator=() is defined.
- pjmlp 5y agoWell, what happens when you call func(A, B) if both are pointers in C? Or if we take an Algol derived language, like Pascal or Modula-2, func might have been defined as, type my_complex_type = .... procedure func(var a, b:my_complex_type); begin end; Raising the same kind of questions. Yes there are issues with C++ approach as you describe, however sometimes it seems C++ hate kind of blinds the people that similar issues occur in other languages to some extent.
- gpderetta 5y agoSpeaking of Algol and argument passing, I'll leave this [1] here... [1] https://en.wikipedia.org/wiki/Man_or_boy_test https://en.wikipedia.org/wiki/Man_or_boy_test
- gpderetta 5y agoDue to function overloading, figuring out which function is called is not exclusively a problem of operators. And IDE can help here (and so does consistency: similarly named functions/operators should behave similarly).