|
|
|
|
|
by stkdump
1436 days ago
|
|
You can predict the outcome very well. It is a call to an operator, which can be trivial for simple types. But of course if you concatenate two 500MB strings using +, you will have a 1GB allocation. I don't see how that is a problem or even a surprise. Of course you could do something in that operator that nobody would expect to happen inside it. But the same is true if you give a function a bad name. For all intents and purposes, an operator is just a function with a particularly short name and (default) style of how it is called. |
|
Not always. BTW, I don't know if you noticed it, but I was exagerating to make a point.
> Of course you could do something in that operator that nobody would expect to happen inside it
To me, this is the problem. For example, I do embedded. I have to know with a certain precision what is going on in my program.
It's a very different thing to call a bad-named or badly-done function. It's an unlucky case... I guess?...
But if I use an operator, there might be hidden code there I have to see.
Yes, I know you can use "=" to copy a struct. But also "a = b + c" might be doing something slow, like re-allocating internal pointers and making copies, allocating new objects, etc. I have to read the code to see what it will do. Believe me, I have done it with inherited embedded C++ projects.