Search

7.8 — Matching function calls to overloaded functions

Making a call to an overloaded function results in one of three possible outcomes:

A best match is found. The call is resolved to a particular overloaded function. No match is found. The arguments can not be matched to any overloaded function. An ambiguous match is found. The arguments matched more than one overloaded function . . . → Read More: 7.8 — Matching function calls to overloaded functions

6.5 — Variable shadowing (name hiding)

Each block defines its own scope region. So what happens when we have a variable inside a nested block that has the same name as a variable in an outer block? When this happens, the nested variable “hides” the outer variable in areas where they are both in scope. This is called name hiding or . . . → Read More: 6.5 — Variable shadowing (name hiding)

10.2 — In and out parameters

Parameters passed by value, const reference, or pointer to const are sometimes called in parameters (short for input parameters) because such parameters are used to send values into the function (the function uses those values as inputs).

However, parameters passed by non-const reference allow a function to modify the value of the argument. If a . . . → Read More: 10.2 — In and out parameters

8.10 — Return by reference and return by address

In previous lessons, we discussed that when passing an argument by value, a copy of the argument is made into the function parameter. For fundamental types (which are cheap to copy), this is fine. But copying is typically expensive for class types (such as std::string), and we can avoid paying this cost by passing by . . . → Read More: 8.10 — Return by reference and return by address

8.11 — Introduction to program-defined types

Because fundamental types have been defined as part of the core C++ language, they are available for immediate use. For example, if we want to define an int variable, we can just do so:

This also works for the compound types that are simple extensions of fundamental types (including pointers, references, and arrays):

. . . → Read More: 8.11 — Introduction to program-defined types

8.3 — Unscoped enumeration input and output

You might be surprised to find out that enumerators are actually just named integral constants (and as a result, enumerated types just hold an integral value).

This is similar to the case with chars (%Failed lesson reference, id XX%). Consider:

A char is really just a small integer, and the character ‘A’ gets converted . . . → Read More: 8.3 — Unscoped enumeration input and output

7.16 — std::cin and handling invalid input

Most programs that have a user interface of some kind need to handle user input. In the programs that you have been writing, you have been using std::cin to ask the user to enter text input. Because text input is so free-form (the user can enter anything), it’s very easy for the user to enter . . . → Read More: 7.16 — std::cin and handling invalid input

7.13 — Code coverage

In the previous lesson 7.12 — Introduction to testing your code, we discussed how to write and preserve simple tests. In this lesson, we’l ltalk about what kind of tests are useful to write to ensure your code is correct.

Code coverage

The term code coverage is used to describe how . . . → Read More: 7.13 — Code coverage

7.5 — Switch fallthrough and scoping

This lesson continues our exploration of switch statements that we started in the prior lesson 7.4 — Switch statement basics. In the prior lesson, we mentioned that each set of statements underneath a label should end in a break statement or a return statement.

In this lesson, we’ll explore why, and talk about some switch . . . → Read More: 7.5 — Switch fallthrough and scoping

7.14 — Common semantic errors in C++

In lesson %Failed lesson reference, id 7940%, we covered syntax errors, which occur when you write code that is not valid according to the grammar of the C++ language. The compiler will notify of you these type of errors, so they are trivial to catch, and usually straightforward to fix.

We also covered semantic errors, . . . → Read More: 7.14 — Common semantic errors in C++