introduction au langage c++
DESCRIPTION
Introduction au langage C++. But. Programmer une classe en C++ permettant de faire du calcul par intervalles L’utiliser pour résoudre un problème de localisation « range only » (EX : plusieurs émetteurs et récepteurs radar qui tentent de localiser un cible). > Sommaire. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/1.jpg)
Introduction au langage C++
![Page 2: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/2.jpg)
Introduction au langage C++21/04/23 2
But
Programmer une classe en C++ permettant de faire du calcul par intervalles
L’utiliser pour résoudre un problème de localisation « range only » (EX : plusieurs émetteurs et récepteurs radar qui tentent de localiser un cible)
![Page 3: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/3.jpg)
Introduction au langage C++21/04/23 3
> Sommaire1. Introduction au langage C++
a) Présentationb) Hello World!c) Namespaced) Référencese) Classesf) Constructeurs/destructeur et surchargeg) Liste d’initialisationh) Opérateursi) Fonctions amiesj) Héritagek) Classes abstraitesl) Autres
![Page 4: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/4.jpg)
Introduction au langage C++21/04/23 4
Introduction au langage C++
![Page 5: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/5.jpg)
Introduction au langage C++21/04/23 5
Présentation
Le C est inclus (à 99%) dans le C++ Le C++ rajoute des notions de programmation
orientée objet (classe, héritage, polymorphisme… comme en Java), ainsi que des facilités d’écriture (surcharge d’opérateurs…)
![Page 6: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/6.jpg)
Introduction au langage C++21/04/23 6
Hello World!
Notion de namespace
Opérateur
![Page 7: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/7.jpg)
Introduction au langage C++21/04/23 7
Namespace
Plus besoin d’utiliser std::
![Page 8: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/8.jpg)
Introduction au langage C++21/04/23 8
Références
Paramètre passé par référence
![Page 9: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/9.jpg)
Introduction au langage C++21/04/23 9
Classes
TestClass.cpp
TestClass.h
Main.cpp
![Page 10: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/10.jpg)
Introduction au langage C++21/04/23 10
Constructeurs/Destructeur et surcharge
TestClass.cppTestClass.h
![Page 11: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/11.jpg)
Introduction au langage C++21/04/23 11
Liste d’initialisation
L’initialisation des membres dans le constructeur peut être faite de cette façon
![Page 12: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/12.jpg)
Introduction au langage C++21/04/23 12
Opérateurs
TestClass.cppTestClass.h
![Page 13: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/13.jpg)
Introduction au langage C++21/04/23 13
Opérateurs
Résultat
Main.cpp
![Page 14: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/14.jpg)
Introduction au langage C++21/04/23 14
Fonctions amies
TestClass.h
![Page 15: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/15.jpg)
Introduction au langage C++21/04/23 15
Fonctions amies
TestClass.cpp
![Page 16: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/16.jpg)
Introduction au langage C++21/04/23 16
Fonctions amies
Main.cpp
![Page 17: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/17.jpg)
Introduction au langage C++21/04/23 17
Héritage
Classe de base
Classe dérivéesAppel à un constructeur spécifique de la classe de base
![Page 18: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/18.jpg)
Introduction au langage C++21/04/23 18
Classes abstraites
Classe de base abstraite
Classe dérivées
![Page 19: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/19.jpg)
Introduction au langage C++21/04/23 19
Classes abstraites
![Page 20: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/20.jpg)
Introduction au langage C++21/04/23 20
Autres apports du C++ par rapport au C
new, delete et new[], delete[] en C++ à la place de malloc() et free() en C pour utiliser des pointeurs et tableaux à taille variable
Mécanisme d’exceptions Templates Classes vector, list…
![Page 21: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/21.jpg)
Introduction au langage C++21/04/23 21
Annexes
![Page 22: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/22.jpg)
Introduction au langage C++21/04/23 22
Le C est inclus (à 99%) dans le C++ : quand on fait du C, on fait aussi du C++ mais l’inverse n’est pas forcément vrai
Du code C ou C++ peut être écrit dans un fichier .cpp mais seul du code C peut être écrit dans un fichier .c
Dans un .h, on peut écrire du C ou du C++, mais il faut que les .c n’incluent que des .h avec du C
![Page 23: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/23.jpg)
Introduction au langage C++21/04/23 23
Différences entre les compilateurs Windows et Linux– Linux
• Le compilateur C le plus utilisé est GCC• Son équivalent C++ est G++
– Windows• GCC/G++ existent avec Cygwin et MinGW• Différents IDE existent et fournissent leurs propres compilateurs
– Microsoft Visual Studio avec CL– Borland C++ Builder / Turbo C++ / Borland Developper
Studio avec BCC32– Code Blocks / Dev-C++ avec MinGW
![Page 24: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/24.jpg)
Introduction au langage C++21/04/23 24
Différences entre les compilateurs Windows et Linux
Equivalences Linux / Windows
Linux/GCC Windows/Visual C++
Fichiers objets .o .obj
Bibliothèque statique .a .lib
Bibliothèque dynamique.so .dll
Exécutable - .exe
![Page 25: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/25.jpg)
Introduction au langage C++21/04/23 25
Utilisation de bibliothèques de fonctions externes
Fichiers .c/.cpp
Fichiers .obj
Fichier .exe
Fichier .lib
Fichier .dll
Compilation
Est utilisée
Edition des liensEdition des liens
Regroupement
Edition des liens
![Page 26: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/26.jpg)
Introduction au langage C++21/04/23 26
Utilisation de bibliothèques de fonctions externes– Cas où on possède des fichiers .h et .c/.cpp
• Exemple : on a Main.cpp qui doit appeler des fonctions déclarées dans Lib.h et définies dans Lib.cpp
– On met #include « Lib.h » dans Main.cpp– On copie Lib.h et Lib.cpp dans le dossier de Main.cpp– On compile et lie Lib.cpp et Main.cpp en les ajoutant au
projet
![Page 27: Introduction au langage C++](https://reader033.vdocuments.pub/reader033/viewer/2022061513/56814a4e550346895db76ed9/html5/thumbnails/27.jpg)
Introduction au langage C++21/04/23 27
Utilisation de bibliothèques de fonctions externes– Cas où on possède des fichiers .h, .lib et .dll
• Exemple : on a Main.cpp qui doit appeler des fonctions déclarées dans Lib.h et définies dans Lib.lib et Lib.dll
– On met #include « Lib.h » dans Main.cpp– On ajoute le dossier de Lib.h dans les chemins de
recherche de fichiers .h du projet– On ajoute le dossier de Lib.lib dans les chemins de
recherche de fichiers .lib du projet– On compile Main.cpp et lie avec Lib.lib en les
ajoutant au projet– On ajoute le dossier de Lib.dll à la variable
d’environnement PATH du système