...

/

Const Propagation for Pointers

Const Propagation for Pointers

Learn about const and different ways to propagate const while using pointers.

We'll cover the following...

Propagation pointers

By using the keyword const, we can inform the compiler about which objects are immutable. The compiler can then check that we don't try to mutate objects that aren't intended to be changed. In other words, the compiler checks our code for const-correctness. A common mistake when writing const-correct code in C++ is that a const-initialized object can still manipulate the values that member pointers point at.

Problem

The following example illustrates the problem:

Access this course and 1400+ top-rated courses and projects.