Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The const keyword in C++ (as applied to parameters and type declarations) is an attempt to keep programmers from shooting off their big toe and taking out their whole leg in the process.</p> <p>The basic idea is to label something as "cannot be modified". A const type can't be modified (by default). A const pointer can't point to a new location in memory. Simple, right?</p> <p>Well, that's where const correctness comes in. Here are some of the possible combinations you can find yourself in when you use const:</p> <p><strong>A const variable</strong> Implies that the data labeled by the variable name cannot be modified.</p> <p><strong>A pointer to a const variable</strong> Implies that the pointer can be modified, but the data itself cannot.</p> <p><strong>A const pointer to a variable</strong> Implies that the pointer cannot be modified (to point to a new memory location), but that the data to which the pointer points <em>can</em> be modified.</p> <p><strong>A const pointer to a const variable</strong> Implies that neither the pointer nor the data to which it points can be modified. </p> <p>Do you see how some things can be goofy there? That's why when you use const, it's important to be correct in which const you are labeling.</p> <p>The point is that this is just a compile-time hack. The labeling just tells the compiler how to interpret instructions. If you cast away from const, you can do whatever you want. But you'll still have to call methods that have const requirements with types that are cast appropriately. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload