prog:cpp:propagate_const
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| prog:cpp:propagate_const [2025/07/06 17:53] – Remise en forme root | prog:cpp:propagate_const [2025/07/06 19:06] (Version actuelle) – Fix value_types root | ||
|---|---|---|---|
| Ligne 128: | Ligne 128: | ||
| <code cpp> | <code cpp> | ||
| + | #include < | ||
| + | |||
| struct Y { | struct Y { | ||
| Y() : m_ptrX(new X()) {}; | Y() : m_ptrX(new X()) {}; | ||
| Ligne 158: | Ligne 160: | ||
| Impossible. | Impossible. | ||
| + | =====indirect_value===== | ||
| + | '' | ||
| + | |||
| + | ====Pointeur==== | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | |||
| + | struct Y { | ||
| + | Y() : m_ptrX(isocpp_p1950:: | ||
| + | |||
| + | void f() const { | ||
| + | std::cout << "f (const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | void f() { | ||
| + | std::cout << "f (non-const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | isocpp_p1950:: | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | Rendu : | ||
| + | |||
| + | < | ||
| + | f (non-const) | ||
| + | g (non-const) | ||
| + | f (const) | ||
| + | g (const) | ||
| + | </ | ||
| + | |||
| + | =====value_types===== | ||
| + | |||
| + | ====Référence==== | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | |||
| + | struct Y { | ||
| + | Y() : m_ptrX(m_X) {}; | ||
| + | |||
| + | void f() const { | ||
| + | std::cout << "f (const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | void f() { | ||
| + | std::cout << "f (non-const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | xyz:: | ||
| + | X m_X; | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | Rendu : | ||
| + | |||
| + | < | ||
| + | f (non-const) | ||
| + | g (non-const) | ||
| + | f (const) | ||
| + | g (const) | ||
| + | </ | ||
| + | |||
| + | ====Pointeur / allocation dynamique==== | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | |||
| + | struct Y | ||
| + | { | ||
| + | Y() : m_ptrX(xyz:: | ||
| + | |||
| + | void f() const { | ||
| + | std::cout << "f (const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | void f() { | ||
| + | std::cout << "f (non-const)\n"; | ||
| + | m_ptrX-> | ||
| + | } | ||
| + | |||
| + | xyz:: | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | Rendu : | ||
| + | |||
| + | < | ||
| + | f (non-const) | ||
| + | g (non-const) | ||
| + | f (const) | ||
| + | g (const) | ||
| + | </ | ||
prog/cpp/propagate_const.1751817197.txt.gz · Dernière modification : de root
