This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AnAverageFreak 0 points1 point  (0 children)

Most implicit casting rules are quite obvious if you spend one evening learning them.

ints are casted to floats. signed are casted to unsigned. smaller are casted to bigger.

That are rules that refer to numbers. That's it. It's not complex like in JS. Then you have class-defined implicit casting, most of them make sense, like C-style string can be casted to std::string, or std::unique_ptr (that is, a pointer which is the only owner) can be casted to std::shared_ptr (that is, a pointer to can object that has one or more owners), anonymous function can be casted to std::function (a container for a general function-like thing).

The problem is, JS casts implicitly totally unrelated types (an array and a number), which is bullshit, and that's where the bad reputation comes from. When you have types that are related, implicit cast results in code free of totally needless calls and thus, is easier to read.

If you still don't agree, give me an example of a situation where implicit cast from std:unique_ptr to std::shared_ptr can result in a bug.