Question sur le code de jeudi 21.11.19 by Céline Guex - Monday, 25 November 2019, 8:13 PM 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. Permalink Reply In reply to Céline Guex Re: Question sur le code de jeudi 21.11.19 by Sepand Kashani - Tuesday, 26 November 2019, 3:02 PM 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; } Permalink Show parent Reply
In reply to Céline Guex Re: Question sur le code de jeudi 21.11.19 by Sepand Kashani - Tuesday, 26 November 2019, 3:02 PM 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; } Permalink Show parent Reply