====Déclaration des variables==== ===Pointeur sur la méthode d'une classe=== {{gh>https://github.com/bansan85/wiki_le_garrec_fr/blob/master/cpp/variable/pointer_function.cpp}} Exemple avec une fonction utilisant des template avec auto déduction. Dans ce cas, il faudra faire un cast pour donner le type des éléments déduits. struct S5 { template void f(U&&...) const { std::cout << "S5" << sizeof...(T) << "-" << sizeof...(U) << "\n"; } }; auto ptr = static_cast(&S5::f) [[https://stackoverflow.com/questions/17874489/disambiguate-overloaded-member-function-pointer-being-passed-as-template-paramet|Disambiguate overloaded member function pointer being passed as template parameter]] {{ :lang:cpp:variable:c_-_disambiguate_overloaded_member_function_pointer_being_passed_as_template_parameter_-_stack_overflow_2021-05-29_08_00_38_.html |Archive du 26/07/2013 le 29/05/2021}} ====Programmation fonctionnelle==== ===Initialisation complexe d'une constante=== Plutôt que {{gh>https://github.com/bansan85/wiki_le_garrec_fr/blob/master/cpp/variable/const_variable_bad.cpp}} écrire {{gh>https://github.com/bansan85/wiki_le_garrec_fr/blob/master/cpp/variable/const_variable_good.cpp}} ====Erreurs==== * ''non-const lvalue reference to type 'X<...>' cannot bind to a temporary of type 'X<...>%%'%%'' Parfois, il n'est pas possible de faire: int i; int& j = i; Il faut alors soit passer par une référence constante : int i; const int& j = i; ou passer par un pointeur : int i; int* j = &i; [[https://stackoverflow.com/questions/18565167/non-const-lvalue-references|Non const lvalue references]] {{ :lang:cpp:variable:c_-_non_const_lvalue_references_-_stack_overflow_2021-11-05_23_19_03_.html |Archive du 02/09/2013 le 05/11/2021}}