Question sur le code de jeudi 21.11.19 par Céline Guex, lundi 25 novembre 2019, 20:13 Number of replies: 1 Bonsoir,Dans la partie du code ci-dessous, issue du code "amis-2019" , à quoi correspond exactement le symbole "->" ?Est-ce une notation équivalente à "element.nom" ?Merci d'avance de votre réponse. Permalien Répondre In reply to Céline Guex Re: Question sur le code de jeudi 21.11.19 par Sepand Kashani, mardi 26 novembre 2019, 15:02 La flèche est une notation qui peux s'utiliser avec des pointeurs sur structures pour simplifier l'accès à leurs attributs. #include <iostream> struct A { int a; int b; }; int main() { A obj = {1, 2}; A* ptr = &obj; std::cout << obj.a << ", " << obj.b << std::endl; // 1, 2 std::cout << (*ptr).a << ", " << (*ptr).b << std::endl; // 1, 2 std::cout << ptr->a << ", " << ptr->b << std::endl; // 1, 2 return 0; } Permalien Niveau supérieur Répondre
In reply to Céline Guex Re: Question sur le code de jeudi 21.11.19 par Sepand Kashani, mardi 26 novembre 2019, 15:02 La flèche est une notation qui peux s'utiliser avec des pointeurs sur structures pour simplifier l'accès à leurs attributs. #include <iostream> struct A { int a; int b; }; int main() { A obj = {1, 2}; A* ptr = &obj; std::cout << obj.a << ", " << obj.b << std::endl; // 1, 2 std::cout << (*ptr).a << ", " << (*ptr).b << std::endl; // 1, 2 std::cout << ptr->a << ", " << ptr->b << std::endl; // 1, 2 return 0; } Permalien Niveau supérieur Répondre