Memory leaks Default parameters Function overloading Operator overloading

  • Slides: 40
Download presentation

 תוכן § מבוא § הרחבות Memory leaks § Default parameters § Function overloading

תוכן § מבוא § הרחבות Memory leaks § Default parameters § Function overloading § Operator overloading § Pointers & references § Function pointer § Late/Early binding § 3 § חזרה § פונקציות § מבנים § הקצאת זכרון דינאמית . © כל הזכויות שמורות. נכתב ע"י יעל ארז

 חזרה – פונקציות Function’s signature A function's signature is a combination of the

חזרה – פונקציות Function’s signature A function's signature is a combination of the function's name; the number, order, and types of its parameters; as well as any qualifiers that can be applied to the function. http: //www. bookrags. com/sciences/computerscience/function-signaturewcs. html 10 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

struct – חזרה שם המבנה members struct point{ int x; int y; }; void

struct – חזרה שם המבנה members struct point{ int x; int y; }; void main() { struct point my_point = { 3, 7 }; struct point *p = &my_point; (*p). x = 8; p->x = 8; } 15 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

 הרחבות Memory leaks § Default parameters § Function overloading § Operator overloading §

הרחבות Memory leaks § Default parameters § Function overloading § Operator overloading § Pointers & references § Function pointer § Late/Early binding § 20 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

Memory leaks – הרחבות CRT library : memory leak detection enabling : כדי שנוכל

Memory leaks – הרחבות CRT library : memory leak detection enabling : כדי שנוכל להשתמש בכלי זה יש להגדיר בתוכנית #define _CRTDBG_MAP_ALLOC #include <stdlib. h> #include <crtdbg. h> ל free ו malloc ממפה את הפונקציות _free_dbug _ ו malloc_dbg _Crt. Dump. Memory. Leaks() כדי לקבל מידע נקרא לפונקציה 21 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

Memory leaks – הרחבות CRT library : memory leak detection enabling : delete ו

Memory leaks – הרחבות CRT library : memory leak detection enabling : delete ו new אם רוצים לעבוד עם #ifdef _DEBUG #ifndef DBG_NEW #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) #define new DBG_NEW #endif // _DEBUG 22 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

Default parameters – הרחבות #include <iostream> using namespace std; void print (int a=1, int

Default parameters – הרחבות #include <iostream> using namespace std; void print (int a=1, int b=2, int c=3) { cout<<"a="<<a<<" b="<<b<<" c="<<c<<endl; } int main() { print(11, 22, 33); print(100, 200); print(17); return 0; } 24 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

Function overloading – הרחבות int add(int a, int b, int c) { cout<<"int, int"<<endl;

Function overloading – הרחבות int add(int a, int b, int c) { cout<<"int, int"<<endl; return a+b+c; } int add(int a, int b, double c) { cout<<"int, double"<<endl; return a+b+c; } 26 . © כל הזכויות שמורות. נכתב ע"י יעל ארז

pointers & references – הרחבות Call by reference void swap(int &a, int &b) {

pointers & references – הרחבות Call by reference void swap(int &a, int &b) { int tmp; tmp=a; a=b; b=tmp; } 32 . © כל הזכויות שמורות. נכתב ע"י יעל ארז