From the course: Debugging in C++ with Visual Studio Code

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Semantic errors

Semantic errors

- [Instructor] Now let's look at some semantic errors. These are related to the compiler's ability to understand the meaning of the code, like type mismatches or referencing an undefined variable. The first one is in line 25. This function is supposed to return a string, but it was declared to return an integer. Looking at the squiggle in line 26, we see that the return value does not match the function type. The solution is to change the function type to string. The next one is in line 45 where &tip is declared as a reference without initialization. My intent was to use &tip as a reference to tipPercentage, which is declared at line 42. So let me fix that. Now we get another squiggle because the type of the reference is int and tip percentage is a double. And the message complaints that a reference of type int, cannot be initialized with a value of type double. So let me change the type from int to double. The next one is in line 62, where an auto variable is declared but not…

Contents