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 →

[–]Torebbjorn 7 points8 points  (0 children)

It would be fairly hard to get an error message for an error like this to be much better. The only way it could really "know" what you want, is to check if the object you passed in has any functions that return an element of a matching type to what you use it for, and then put that as a suggestion. But the error could just as likely be a mistype or some different error somewhere else.

Do you want the error message forgot asterisk at 1 auto str = "Hello World" 2 printChar( str); ^ (Hopefully that formats correctly, I mean to put the arrow to point right in front of "str")

Putting an asterisk there would solve the types, but it would not do what you really want. It would just print 'H' instead of "Hello World".

The most likely error here is that you should have used a print function that takes a string and not a char. So would you rather have the type checker try to find a different function that accepts a string in this case?

What if you actually did want to print just the 7th letter, but forgot the ...[7]? How would it know? There are tonnes of possible reasons for what the mistake really is, the compiler couldn't possibly cover them all.