SlideShare a Scribd company logo
C++ 
L09 -Classes, P2 
Programming Language 
Mohammad Shaker 
mohammadshaker.com 
@ZGTRShaker 
2010, 11, 12, 13, 14
ClassesComposition
ClassesCompositionClass has object of other classes as members“has –a ” relation
Composition 
#include<iostream> 
usingnamespacestd; 
#ifndefdate_h 
#definedate_h 
classdate 
{ 
public: 
date(int= 1, int= 1, int= 1990); 
voidprint()const; 
~date(); 
private: 
intday, month, year; 
}; 
date::date(intd, intm, inty) 
{day = d; month = m, year = y; 
cout << "Constructor runs for date class “;print();} 
voiddate::print() const 
{cout << day << "/"<< month << "/"<< year << endl; } 
date::~date() 
{cout << "destructor runs for date class, which date is:"<< endl;print(); 
} 
#endif
Composition 
#include<iostream> 
#include"date.h" 
usingnamespacestd; 
#ifndefemployee_h 
#defineemployee_h 
classemployee 
{ 
public: 
employee(); 
employee(char*First, 
char*Last, 
constdate& d1, 
constdate& d2); 
voidprint()const; 
~employee(); 
private: 
charFirstName [20]; 
charLastName [20]; 
constdate hiredate; 
constdate birthdate; 
}; 
employee::employee(char*First, char*Last,constdate& d1, constdate& d2):birthdate(d1), hiredate(d2) 
{ 
intLength = strlen(First); 
strncpy(FirstName,First,20); 
FirstName[Length]='0'; 
strncpy(LastName,Last,20); 
LastName[Length]='0'; 
cout<<“Constructor runs for employee:"<<FirstName<<' '<< LastName<<endl; 
// ' ' space char;) 
} 
voidemployee::print() const 
{ 
cout << "Employee: "<< FirstName << ' '<< LastName << endl; 
cout << "printing dates for this employee"<< endl; 
birthdate.print(); 
hiredate.print(); 
cout << "________________"<< endl; 
} 
employee::~employee() 
{ 
cout << "destructor runs for employee class, for "; 
print(); 
} 
#endif
Composition 
#include<iostream> 
#include"employee.h" 
#include"date.h" 
usingnamespacestd; 
voidmain() 
{ 
date Birth (15,12,1990); 
date Hire (28,7,2010); 
employee manager ("mee", "loo", Birth, Hire ); 
manager.print(); 
} 
Constructor runs for date class 15/12/1990 
Constructor runs for date class 28/7/2010 
Constructor runs for employee:mee Hee 
Employee: mee Hee 
printing dates for this employee 
15/12/1990 
28/7/2010 
________________ 
destructor runs for employee class, for Employee: mee Hee 
printing dates for this employee 
15/12/1990 
28/7/2010 
________________ 
destructor runs for date class, which date is: 
15/12/1990 
destructor runs for date class, which date is: 
28/7/2010 
destructor runs for date class, which date is: 
28/7/2010 
destructor runs for date class, which date is: 
15/12/1990 
Press any key to continue
Composition 
classemployee 
{ 
public: 
employee(); 
employee(char*First, 
char*Last, 
constdate& d1, 
constdate& d2); 
voidprint()const; 
~employee(); 
private: 
charFirstName [20]; 
charLastName [20]; 
constdate hiredate; 
constdate birthdate; 
}; 
classemployee 
{ 
public: 
employee(); 
employee(char*First, 
char*Last, 
constdate& d1, 
constdate& d2); 
voidprint()const; 
~employee(); 
private: 
charFirstName [20]; 
charLastName [20]; 
const date birthdate;// we change this 
const date hiredate;// we change this 
}; 
Change this to
Composition 
#include<iostream> 
#include"employee.h" 
#include"date.h" 
usingnamespacestd; 
voidmain() 
{ 
date Birth (15,12,1990); 
date Hire (28,7,2010); 
employee manager ("mee", "loo", Birth, Hire ); 
manager.print(); 
} 
Constructor runs for date class 15/12/1990 
Constructor runs for date class 28/7/2010 
constructor runs for employee:mee Hee 
Employee: mee Hee 
printing dates for this employee 
15/12/1990 
28/7/2010 
________________ 
destructor runs for employee class, for Employee: mee Hee 
printing dates for this employee 
15/12/1990 
28/7/2010 
________________ 
destructor runs for date class, which date is: 
28/7/2010 
destructor runs for date class, which date is: 
15/12/1990 
destructor runs for date class, which date is: 
28/7/2010 
destructor runs for date class, which date is: 
15/12/1990 
Press any key to continue 
So! 
Member objects are constructed in order declared and not in order of constructor’s member initializer list!
friend Functions
friendFunctions 
•friend Functions 
–A function that is defined outside the scope of the class 
–A non-member function of class 
•But has access to its private data members! 
–The world “friend ” is appears only in the function prototype (in the class definition) 
–Escaping data-hiding restriction 
–Benefits: 
•friend function can be used to access more than one class!
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
Count(): x(0) {} 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
voidWrong() 
{ 
Count C; 
C.x = 3; 
} 
#endif 
Compiler error Can’t access private date members
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
Count(): x(0) {} 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
#endif 
Compiler error Can’t access private date members 
#include<iostream> 
#include"count.h" 
usingnamespace::std; 
voidWrong() 
{ 
Count C; 
C.x = 3; 
} 
voidmain() 
{ 
Wrong(); 
}
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
friendvoidPlay (); 
Count(): x(0) {}; 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
voidPlay() 
{ 
Count C; 
C.x = 3; 
} 
#endif 
Compile and run 
#include<iostream> 
#include"count.h" 
usingnamespace::std; 
voidWrong() 
{ 
Count C; 
C.x = 3; 
} 
voidmain() 
{ 
Wrong(); 
}
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
friendvoidPlay (); 
Count(): x(0) {}; 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
#endif 
Compile and run 
#include<iostream> 
#include"count.h" 
usingnamespace::std; 
voidPlay() 
{ 
Count C; 
C.x = 3; 
} 
voidmain() 
{ 
}
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
friendvoidPlay (Count &C); 
Count(): x(0) {}; 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
voidPlay(Count &C) 
{ 
C.x = 3; 
} 
#endif 
0 
3 
Press any key to continue 
#include<iostream> 
#include"count.h" 
usingnamespace::std; 
voidmain() 
{ 
Count CooCoo; 
CooCoo.print(); 
Play(CooCoo); 
CooCoo.print(); 
}
#include<iostream> 
#include"count.h" 
usingnamespace::std; 
friendvoidStillWrong() 
{ 
Count C; 
C.x = 3; 
} 
voidmain() 
{ 
StillWrong(); 
} 
friendFunctions 
#include<iostream> 
usingnamespacestd; 
#ifndefCount_H 
#defineCount_H 
classCount 
{ 
public: 
friendvoidPlay (Count &C); 
Count(): x(0) {}; 
voidprint()const{cout << x << endl;}; 
private: 
intx; 
}; 
voidPlay(Count &C) 
{ 
C.x = 3; 
} 
#endif 
Compiler error we write the “friend” key word in the function defintion!
friendClasses
friend Classes 
•Properties of friendship 
–Granted not taken 
•class B is a friend of class A 
–class A must explicitly declare class B as friend 
–Not symmetric 
•class B friend of class A 
–class A not necessarily friend of class B! 
–Not transitive 
•A friend of B 
•B friend of C 
–A not necessarily friend of C!
friendClasses 
#include<iostream> 
#include"_2ndClass.h" 
usingnamespacestd; 
class_1stClass 
{ 
public: 
friendclass_2nClass; // declaring _2ntClass 
// as friend to _1stClass 
private: 
intx; 
}; 
#include<iostream> 
usingnamespacestd; 
#ifndef_2ndClass_h 
#define_2ndClass_h 
class_2ndClass 
{ 
public: 
private: 
intx; 
}; 
#endif 
In _2ndClass header 
In _1stClass header 
#include<iostream> 
usingnamespacestd; 
class_1stClass 
{ 
public: 
friendclass_2nClass; 
private: 
constintx; 
}; 
class_2ndClass 
{ 
public: 
voidPlayWith_1stClass(_1stClass C1); 
private: 
inty; 
}; 
void_2ndClass::PlayWith_1stClass(_1stClass C1) 
{ 
y = C1.x; 
} 
Now it’s all okay
thisKeyword
thisKeyword 
•“this” pointer 
–Represent the address memory of the object 
–Its values is always the memory address of the object 
–Can be used 
•Explicitly implicitly 
–What’s used for? 
•Can be used to check if a parameter passed to a member function of an object is the object itself 
•Cascading 
–Multiple function invoked in the same statement
thisKeyword 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test():x(){}; 
voidChange(int); 
voidprint() const; 
private: 
intx; 
}; 
voidTest::print() const 
{ 
cout << x << endl; 
cout << this->x << endl; 
cout << (*this).x << endl; 
} 
voidTest::Change (intnewValue) 
{ 
x = newValue; 
} 
#include<iostream> 
#include“Test.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
T.print(); 
T.Change(6); 
T.print(); 
} 
0 
0 
0 
6 
6 
6 
Press any key to continue
thisKeyword 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test():x(){}; 
voidChange(int); 
voidprint() const; 
private: 
intx; 
}; 
voidTest::print() const 
{ 
cout << x << endl; 
cout << this->x << endl; 
cout << *this.x << endl; 
} 
voidTest::Change (intnewValue) 
{ 
x = newValue; 
} 
*this.x != (*this).x because the (.) has higher precedence than (*) So,Compiler error!
thisKeyword 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test():x(){}; 
voidIsSame(Test &Tempo); 
voidprint() const; 
private: 
intx; 
}; 
voidTest::print() const 
{ 
cout << x << endl; 
} 
voidTest::IsSame (Test &Tempo) 
{ 
if(this== &Tempo) 
{ 
cout << "References are the same"<< endl; 
} 
} 
0 
References are the same 
Press any key to continue 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
Test *Tptr = &T; 
T.print(); 
Tptr->IsSame(T); 
}
thisKeyword 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test():x(){}; 
voidIsSame(Test &Tempo); 
voidprint() const; 
private: 
intx; 
}; 
voidTest::print() const 
{ 
cout << x << endl; 
} 
voidTest::IsSame (Test Tempo) 
{ 
if(this== &Tempo) 
{ 
cout << "References are the same"<< endl; 
} 
} 
0 
Press any key to continue 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
Test *Tptr = &T; 
T.print(); 
Tptr->IsSame(T); 
} 
Cause it’s passed by value not reference
thisKeyword 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test():x(){}; 
voidIsSame(Test &Tempo); 
voidprint() const; 
private: 
intx; 
}; 
voidTest::print() const 
{ 
cout << x << endl; 
} 
voidTest::IsSame (Test &Tempo) 
{ 
if(this== &Tempo) 
{ 
cout << "References are the same"<< endl; 
} 
} 
0 
References are the same 
Press any key to continue 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
Test *Tptr = &T; 
T.print(); 
T.IsSame(*Tptr); 
}
thisKeyword 
classTime 
{public: 
Time(); 
Time &SetTime(int,int,int); // set functions 
Time &SetHour(int); 
Time &SetMinute(int); 
Time &SetSecond(int); 
intGetHour(); // get functions 
intGetMinute(); 
intGetSecond(); 
voidPrintTime(); 
private: inthour;intminute;intsecond; }; 
Time::Time() 
{hour = minute = second = 0; }; 
Time &Time::SetTime(intxhour,intxminute, intxsecond) 
{SetHour(xhour);SetMinute(xminute);SetSecond(xsecond); 
return*this;// enabling cascading 
}; 
Time &Time::SetHour(inth) { hour = (h>=0 && h<24)? h: 0; 
return*this;// enabling cascading 
}; 
Time &Time::SetMinute(intm) { minute = (m>=0 && m<60)? m: 0; 
return*this;// enabling cascading 
}; 
Time &Time::SetSecond(ints) { second = (s>=0 && s<60)? s: 0; 
return*this;// enabling cascading 
}; 
intTime::GetHour() {returnhour;}; 
intTime::GetMinute() {returnminute;}; 
intTime::GetSecond() {returnsecond;}; 
voidTime::PrintTime() 
{cout << hour << ":"<< minute << ":"<< second << endl; } 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Time T; 
//cascade member calls 
T.SetHour(12).SetMinute(5).SetSecond(2); 
T.PrintTime(); 
}
static Class Members
static Class Members 
•Static members variables are shared among all instances of class 
–Keeps track of how many objects have been created 
•Incrementing with each constructing 
•Decrementing with each destructing 
–Must be initialized 
•Only once 
•Out side the class 
–Can be 
•public, private or protected
static Class Members 
•Accessible through public member function or friends 
–Public static variables 
•When no object of class exists 
–Private static variables 
•When no object of class exists 
•Can be accessed via public static member functions 
•Can’t access non-static data or functions, why? 
•No thispointer for staticfunctions, why?
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << SVariable << endl;SVariable--;}; 
private: 
staticintSVariable; 
}; 
// initialize just once outside the scope of the class 
intTest::SVariable = 5; 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
} 
5 
6 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << SVariable << endl;--SVariable;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T; 
cout << T.SVariable<<endl; 
} 
5 
6 
6 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << "const "<< SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl;SVariable- -;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
{ 
Test T; 
cout << T.SVariable << endl; 
} 
cout << Test::SVariable << endl; 
} 
const 5 
6 
dest 6 
5 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << "const "<< SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl;SVariable- -;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
{ 
Test T[5]; 
cout << Test::SVariable << endl; 
} 
cout << Test::SVariable << endl; 
} 
const 5 
const 6 
const 7 
const 8 
const 9 
10 
dest 10 
dest 9 
dest 8 
dest 7 
dest 6 
5 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << "const "<< SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl;SVariable- -;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
{ 
Test *T = newTest[5]; 
cout << Test::SVariable << endl; 
} 
cout << Test::SVariable << endl; 
} 
const 5 
const 6 
const 7 
const 8 
const 9 
10 
10 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << "const "<< SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl;SVariable- -;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
{ 
Test *T = newTest[5]; 
cout << Test::SVariable << endl; 
delete[] T; 
} 
cout << Test::SVariable << endl; 
cout << Test::SVariable << endl; 
} 
const 5 
const 6 
const 7 
const 8 
const 9 
10 
dest 10 
dest 9 
dest 8 
dest 7 
dest 6 
5 
5 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{cout << "const "<< SVariable << endl; SVariable++;}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl;SVariable- -;}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
{ 
Test *T = newTest[5]; 
cout << Test::SVariable << endl; 
} 
cout << Test::SVariable << endl; 
delete[] T; 
cout << Test::SVariable << endl; 
} 
Compile error. Undeclared identifier T 
We did allocate memory and we have never been de-allocated it!
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T1; 
Test T2; 
} 
const 1 
const 2 
dest 1 
dest 0 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test *T1; 
Test *T2; 
} 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1; 
Test *T2; 
//cout << T1->SGet() << endl; 
} 
const 1 
dest 0 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = &TSource; 
Test *T2; 
} 
const 1 
dest 0 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
} 
const 1 
const 2 
dest 1 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
cout << T1->SGet() << endl; 
} 
const 1 
const 2 
2 
dest 1 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
cout << Test::SGet() << endl; 
} 
const 1 
const 2 
2 
dest 1 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
deleteT1; 
cout << Test::SGet() << endl; 
} 
const 1 
const 2 
dest 1 
1 
dest 0 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
deleteT1; 
cout << T1->SGet() << endl; 
} 
const 1 
const 2 
dest 1 
1 
dest 0 
Press any key to continue
static Class Members 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{++SVariable; 
cout << "const "<< SVariable << endl; 
}; 
voidprint() const; 
~Test() 
{--SVariable; 
cout << "dest "<< SVariable << endl; 
}; 
staticintSGet();// static member function 
private: 
staticintSVariable;// static date member 
}; 
intTest::SVariable = 0;// initialize just once outside the scope of the class 
voidTest::print() const 
{cout << SVariable << endl;} 
intTest::SGet() 
{ 
returnSVariable; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test TSource; 
Test *T1 = newTest; 
Test *T2; 
delete[]T1; 
cout << T1->SGet() << endl; 
} 
Runtime error coz of [] not compiler error for sure!
static Class Members 
#include <iostream> 
using namespace::std; 
class TestStaticClass 
{ 
public: 
static inti; 
static void StaticPublicMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
} 
}; 
intTestStaticClass::i= 0; 
void main() 
{ 
TestStaticClassT; 
T.StaticPublicMethodTest(); 
TestStaticClass::StaticPublicMethodTest(); 
system("pause"); 
} 
You called a static method! 
You called a static method! 
Press any key to continue
static Class Members 
#include <iostream> 
using namespace::std; 
class TestStaticClass 
{ 
public: 
void GetMyName() 
{ 
cout<< "You are in "TestStaticClass" class" << endl; 
} 
static void StaticPublicMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
} 
}; 
void main() 
{ 
TestStaticClassT; 
T.GetMyName(); 
TestStaticClass::GetMyName(); 
system("pause"); 
} 
Compiler error!, TestStaticClass::GetMyName();is not static!
static Class Members 
#include <iostream> 
using namespace::std; 
class TestStaticClass 
{ 
public: 
void GetMyName() 
{ 
cout<< "You are in "TestStaticClass" class" << endl; 
} 
static void StaticPublicMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
} 
}; 
void main() 
{ 
TestStaticClassT; 
T.GetMyName(); 
system("pause"); 
} 
You are in "TestStaticClass" class 
Press any key to continue
static Class Members 
#include <iostream> 
using namespace::std; 
class TestStaticClass 
{ 
public: 
void GetMyName() 
{ 
cout<< "You are in "TestStaticClass" class" << endl; 
StaticPublicMethodTest(); 
} 
static void StaticPublicMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
} 
}; 
void main() 
{ 
TestStaticClassT; 
T.GetMyName(); 
system("pause"); 
} 
You are in "TestStaticClass" class 
You called a static method! 
Press any key to continue 
class TestClass 
{ 
public: 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
} 
}; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
system("pause"); 
} 
You called a non static method! 
You called a static method! 
Press any key to continue
static Class Members 
class TestClass 
{ 
public: 
intiNonStatic; 
static intiStatic; 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
iStatic= 5; 
} 
}; 
intTestClass::iStatic= 0; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
cout<< TestClass::iStatic<< endl; 
system("pause"); 
} 
You called a non static method! 
You called a static method! 
5 
Press any key to continue 
class TestClass 
{ 
public: 
intiNonStatic; 
static intiStatic; 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
iStatic= 5; 
iNonStatic= 5; 
} 
}; 
intTestClass::iStatic= 0; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
cout<< TestClass::iStatic<< endl; 
cout<< T.iNonStatic<< endl; 
system("pause"); 
} 
Compile error iNonStatic= 5; 
In “PublicStaticMethodTest” 
Static method!
static Class Members 
class TestClass 
{ 
public: 
intiNonStatic; 
static intiStatic; 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
iNonStatic= 5; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
iStatic= 5; 
} 
}; 
intTestClass::iStatic= 0; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
cout<< TestClass::iStatic<< endl; 
cout<< T.iNonStatic<< endl; 
system("pause"); 
} 
You called a non static method! 
You called a static method! 
5 
5 
Press any key to continue 
class TestClass 
{ 
public: 
intiNonStatic; 
static intiStatic; 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
iNonStatic= 5; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
this.iStatic= 5; 
} 
}; 
intTestClass::iStatic= 0; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
cout<< TestClass::iStatic<< endl; 
cout<< T.iNonStatic<< endl; 
system("pause"); 
} 
This can’t be used in a static method! 
It’s logically wrong!
static Class Members
static Class Members 
class TestClass 
{ 
public: 
intiNonStatic; 
static intiStatic; 
void PublicNonStaticMethodTest() 
{ 
cout<< "You called a non static method!" << endl; 
this.iNonStatic= 5; 
PublicStaticMethodTest(); 
} 
static void PublicStaticMethodTest() 
{ 
cout<< "You called a static method!" << endl; 
iStatic= 5; 
} 
}; 
intTestClass::iStatic= 0; 
void main() 
{ 
TestClassT; 
T.PublicNonStaticMethodTest(); 
cout<< TestClass::iStatic<< endl; 
cout<< T.iNonStatic<< endl; 
system("pause"); 
} 
Compiler error
static Class Members
Important Example
Constructors and Destructors 
#include <iostream> 
using namespace::std; 
class TestClass 
{ 
public: 
char* _name; 
TestClass(char *name) 
{ 
this->_name = name; 
cout<< "Constructor for" << _name << endl; 
} 
~TestClass() 
{ 
cout<< "Destructor for" << _name << endl; 
} 
}; 
void main() 
{ 
TestClassT1("T1"); 
{ 
TestClassT2("T2"); 
static TestClassTStaticInMainInnerScope("TStaticInMainInnerScope"); 
} 
static TestClassTStaticInMainOuterScope("TStaticInMainOuterScope"); 
TestClassT4("T4"); 
} 
TestClassTGlobal("TGlobal"); 
static TestClassTStaticGlobal("TStaticGlobal"); 
Constructor forTGlobal 
Constructor forTStaticGlobal 
Constructor forT1 
Constructor forT2 
Constructor forTStaticInMainInnerScope 
Destructor forT2 
Constructor forTStaticInMainOuterScope 
Constructor forT4 
Destructor forT4 
Destructor forT1 
Destructor forTStaticInMainOuterScope 
Destructor forTStaticInMainInnerScope 
Destructor forTStaticGlobal 
Destructor forTGlobal 
Press any key to continue
Quiz
Quiz #1 
#include<iostream> 
#include"date.h" 
usingnamespacestd; 
#ifndefemployee_h 
#defineemployee_h 
classemployee 
{ 
public: 
employee(); 
employee(char*First, 
char*Last, 
constdate& d1, 
constdate& d2); 
voidprint()const; 
~employee(); 
private: 
charFirstName [20]; 
charLastName [20]; 
constdate hiredate; 
constdate birthdate; 
}; 
employee::employee(char*First, char*Last,constdate& d1, constdate& d2):birthdate(d1), hiredate(d2) 
{ 
intLength = strlen(First); 
strncpy(FirstName,First,20); 
FirstName[Length]='0'; 
strncpy(LastName,Last,20); 
LastName[Length]='0'; 
cout<<"constructor runs for employee:"<<FirstName<<' '<< LastName<<endl; 
// ' ' space char;) 
} 
voidemployee::print() const 
{ 
cout << "Employee: "<< FirstName << ' '<< LastName << endl; 
cout << "printing dates for this employee"<< endl; 
birthdate.print(); 
hiredate.print(); 
cout << "________________"<< endl; 
} 
employee::~employee() 
{ 
cout << "destructor runs for employee class, for "; 
print(); 
} 
#endif
Quiz #1, What’s the Output? 
#include<iostream> 
#include"employee.h" 
#include"date.h" 
usingnamespacestd; 
voidmain() 
{ 
date Birth1 (8,8,1990); 
date Hire1 (4,4,2010); 
date Birth2 (10,10,1990); 
date Hire2 (5,5,2010); 
employee manager1 ("mee", "loo", Birth1, Hire1 ); 
employee manager2 ("zee", "HooHoo", Birth2, Hire2 ); 
manager1.print(); 
manager2.print(); 
} 
#include<iostream> 
usingnamespacestd; 
#ifndefdate_h 
#definedate_h 
classdate 
{ 
public: 
date(int= 1, int= 1, int= 1990); 
voidprint()const; 
~date(); 
private: 
intday, month, year; 
}; 
date::date(intd, intm, inty) 
{day = d; month = m, year = y; 
cout << "Constructor runs for date class “;print();} 
voiddate::print() const 
{cout << day << "/"<< month << "/"<< year << endl; } 
date::~date() 
{cout << "destructor runs for date class, which date is:"<<endl; 
print(); 
} 
#endif
Quiz #1 
destructor runs for employee class, for Employee: zee HooHoo 
printing dates for this employee 
10/10/1990 
5/5/2010 
________________ 
destructor runs for date class, which date is: 
5/5/2010 
destructor runs for date class, which date is: 
10/10/1990 
destructor runs for employee class, for Employee: mee Hee 
printing dates for this employee 
8/8/1990 
4/4/2010 
________________ 
destructor runs for date class, which date is: 
4/4/2010 
destructor runs for date class, which date is: 
8/8/1990 
destructor runs for date class, which date is: 
5/5/2010 
destructor runs for date class, which date is: 
10/10/1990 
destructor runs for date class, which date is: 
4/4/2010 
destructor runs for date class, which date is: 
8/8/1990 
Constructor runs for date class 8/8/1990 
Constructor runs for date class 4/4/2010 
Constructor runs for date class 10/10/1990 
Constructor runs for date class 5/5/2010 
constructor runs for employee:mee Hee 
constructor runs for employee:zee HooHoo 
Employee: mee Hee 
printing dates for this employee 
8/8/1990 
4/4/2010 
________________ 
Employee: zee HooHoo 
printing dates for this employee 
10/10/1990 
5/5/2010 
________________
Quiz #2, What’s the Output? 
#include<iostream> 
usingnamespacestd; 
classTest 
{ 
public: 
Test() 
{ 
cout << "const "<< SVariable << endl; 
SVariable++; 
}; 
voidprint() const; 
~Test() 
{cout << "dest "<< SVariable << endl; 
SVariable--; 
}; 
staticintSVariable; 
private: 
}; 
intTest::SVariable = 5; 
voidTest::print() const 
{ 
cout << SVariable << endl; 
} 
#include<iostream> 
#include"MyFile.h" 
usingnamespacestd; 
voidmain() 
{ 
Test T1; 
{ 
Test T2[5]; 
Test TTemp; 
cout << TTemp.SVariable << endl; 
} 
cout << Test::SVariable << endl; 
Test *T3 = &T1; 
staticTest T4; 
cout << Test::SVariable << endl; 
Test* &T5 = T3; 
cout << Test::SVariable << endl; 
} 
const 5 
const 6 
const 7 
const 8 
const 9 
const 10 
const 11 
12 
dest 12 
dest 11 
dest 10 
dest 9 
dest 8 
dest 7 
6 
const 6 
7 
7 
dest 7 
dest 6

More Related Content

What's hot

C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
Mohammad Shaker
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
Mohammad Shaker
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
kinan keshkeh
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
C++11
C++11C++11
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуля
Sergey Platonov
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
OdessaFrontend
 
c programming
c programmingc programming
c programming
Arun Umrao
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
Intro C# Book
 
Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
रमन सनौरिया
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
Seok-joon Yun
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
ssuserd6b1fd
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
ssuserd6b1fd
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
Dr. Md. Shohel Sayeed
 
Advanced python
Advanced pythonAdvanced python
Advanced python
EU Edge
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
Intro C# Book
 
c programming
c programmingc programming
c programming
Arun Umrao
 
Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
Zaar Hai
 

What's hot (20)

C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
C++11
C++11C++11
C++11
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуля
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
 
c programming
c programmingc programming
c programming
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
c programming
c programmingc programming
c programming
 
Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
 

Viewers also liked

C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
Mohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
Mohammad Shaker
 
C# Starter L05-LINQ
C# Starter L05-LINQC# Starter L05-LINQ
C# Starter L05-LINQ
Mohammad Shaker
 
WPF L03-3D Rendering and 3D Animation
WPF L03-3D Rendering and 3D AnimationWPF L03-3D Rendering and 3D Animation
WPF L03-3D Rendering and 3D Animation
Mohammad Shaker
 
WPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and AnimationWPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and Animation
Mohammad Shaker
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Mohammad Shaker
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-Utilities
Mohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Mohammad Shaker
 
C# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upC# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upMohammad Shaker
 

Viewers also liked (9)

C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
C# Starter L05-LINQ
C# Starter L05-LINQC# Starter L05-LINQ
C# Starter L05-LINQ
 
WPF L03-3D Rendering and 3D Animation
WPF L03-3D Rendering and 3D AnimationWPF L03-3D Rendering and 3D Animation
WPF L03-3D Rendering and 3D Animation
 
WPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and AnimationWPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and Animation
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-Utilities
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
C# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-upC# Starter L01-Intro and Warm-up
C# Starter L01-Intro and Warm-up
 

Similar to C++ L09-Classes Part2

Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
rehan16091997
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
SushmaGavaraskar
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
Phil Calçado
 
Constants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptxConstants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptx
DrJasmineBeulahG
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
Ali Parmaksiz
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
Pritam Samanta
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
Mario Alexandro Santini
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
CharuJain396881
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
Thesis Scientist Private Limited
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
R696
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
Day 1
Day 1Day 1
L10
L10L10
L10
lksoo
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
This code currently works... Run it and get a screen shot of its .docx
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docx
Komlin1
 
Oops presentation
Oops presentationOops presentation
Oops presentation
sushamaGavarskar1
 

Similar to C++ L09-Classes Part2 (20)

Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
 
Constants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptxConstants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptx
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Day 1
Day 1Day 1
Day 1
 
L10
L10L10
L10
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
This code currently works... Run it and get a screen shot of its .docx
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docx
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 

More from Mohammad Shaker

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
Mohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
Mohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
Mohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
Mohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
Mohammad Shaker
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
Mohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
Mohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
Mohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
Mohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
Mohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
Mohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
Mohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
Mohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
Mohammad Shaker
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
Mohammad Shaker
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
Mohammad Shaker
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to Games
Mohammad Shaker
 

More from Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to Games
 

Recently uploaded

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 

Recently uploaded (20)

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 

C++ L09-Classes Part2

  • 1. C++ L09 -Classes, P2 Programming Language Mohammad Shaker mohammadshaker.com @ZGTRShaker 2010, 11, 12, 13, 14
  • 3. ClassesCompositionClass has object of other classes as members“has –a ” relation
  • 4. Composition #include<iostream> usingnamespacestd; #ifndefdate_h #definedate_h classdate { public: date(int= 1, int= 1, int= 1990); voidprint()const; ~date(); private: intday, month, year; }; date::date(intd, intm, inty) {day = d; month = m, year = y; cout << "Constructor runs for date class “;print();} voiddate::print() const {cout << day << "/"<< month << "/"<< year << endl; } date::~date() {cout << "destructor runs for date class, which date is:"<< endl;print(); } #endif
  • 5. Composition #include<iostream> #include"date.h" usingnamespacestd; #ifndefemployee_h #defineemployee_h classemployee { public: employee(); employee(char*First, char*Last, constdate& d1, constdate& d2); voidprint()const; ~employee(); private: charFirstName [20]; charLastName [20]; constdate hiredate; constdate birthdate; }; employee::employee(char*First, char*Last,constdate& d1, constdate& d2):birthdate(d1), hiredate(d2) { intLength = strlen(First); strncpy(FirstName,First,20); FirstName[Length]='0'; strncpy(LastName,Last,20); LastName[Length]='0'; cout<<“Constructor runs for employee:"<<FirstName<<' '<< LastName<<endl; // ' ' space char;) } voidemployee::print() const { cout << "Employee: "<< FirstName << ' '<< LastName << endl; cout << "printing dates for this employee"<< endl; birthdate.print(); hiredate.print(); cout << "________________"<< endl; } employee::~employee() { cout << "destructor runs for employee class, for "; print(); } #endif
  • 6. Composition #include<iostream> #include"employee.h" #include"date.h" usingnamespacestd; voidmain() { date Birth (15,12,1990); date Hire (28,7,2010); employee manager ("mee", "loo", Birth, Hire ); manager.print(); } Constructor runs for date class 15/12/1990 Constructor runs for date class 28/7/2010 Constructor runs for employee:mee Hee Employee: mee Hee printing dates for this employee 15/12/1990 28/7/2010 ________________ destructor runs for employee class, for Employee: mee Hee printing dates for this employee 15/12/1990 28/7/2010 ________________ destructor runs for date class, which date is: 15/12/1990 destructor runs for date class, which date is: 28/7/2010 destructor runs for date class, which date is: 28/7/2010 destructor runs for date class, which date is: 15/12/1990 Press any key to continue
  • 7. Composition classemployee { public: employee(); employee(char*First, char*Last, constdate& d1, constdate& d2); voidprint()const; ~employee(); private: charFirstName [20]; charLastName [20]; constdate hiredate; constdate birthdate; }; classemployee { public: employee(); employee(char*First, char*Last, constdate& d1, constdate& d2); voidprint()const; ~employee(); private: charFirstName [20]; charLastName [20]; const date birthdate;// we change this const date hiredate;// we change this }; Change this to
  • 8. Composition #include<iostream> #include"employee.h" #include"date.h" usingnamespacestd; voidmain() { date Birth (15,12,1990); date Hire (28,7,2010); employee manager ("mee", "loo", Birth, Hire ); manager.print(); } Constructor runs for date class 15/12/1990 Constructor runs for date class 28/7/2010 constructor runs for employee:mee Hee Employee: mee Hee printing dates for this employee 15/12/1990 28/7/2010 ________________ destructor runs for employee class, for Employee: mee Hee printing dates for this employee 15/12/1990 28/7/2010 ________________ destructor runs for date class, which date is: 28/7/2010 destructor runs for date class, which date is: 15/12/1990 destructor runs for date class, which date is: 28/7/2010 destructor runs for date class, which date is: 15/12/1990 Press any key to continue So! Member objects are constructed in order declared and not in order of constructor’s member initializer list!
  • 10. friendFunctions •friend Functions –A function that is defined outside the scope of the class –A non-member function of class •But has access to its private data members! –The world “friend ” is appears only in the function prototype (in the class definition) –Escaping data-hiding restriction –Benefits: •friend function can be used to access more than one class!
  • 11. friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: Count(): x(0) {} voidprint()const{cout << x << endl;}; private: intx; }; voidWrong() { Count C; C.x = 3; } #endif Compiler error Can’t access private date members
  • 12. friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: Count(): x(0) {} voidprint()const{cout << x << endl;}; private: intx; }; #endif Compiler error Can’t access private date members #include<iostream> #include"count.h" usingnamespace::std; voidWrong() { Count C; C.x = 3; } voidmain() { Wrong(); }
  • 13. friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: friendvoidPlay (); Count(): x(0) {}; voidprint()const{cout << x << endl;}; private: intx; }; voidPlay() { Count C; C.x = 3; } #endif Compile and run #include<iostream> #include"count.h" usingnamespace::std; voidWrong() { Count C; C.x = 3; } voidmain() { Wrong(); }
  • 14. friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: friendvoidPlay (); Count(): x(0) {}; voidprint()const{cout << x << endl;}; private: intx; }; #endif Compile and run #include<iostream> #include"count.h" usingnamespace::std; voidPlay() { Count C; C.x = 3; } voidmain() { }
  • 15. friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: friendvoidPlay (Count &C); Count(): x(0) {}; voidprint()const{cout << x << endl;}; private: intx; }; voidPlay(Count &C) { C.x = 3; } #endif 0 3 Press any key to continue #include<iostream> #include"count.h" usingnamespace::std; voidmain() { Count CooCoo; CooCoo.print(); Play(CooCoo); CooCoo.print(); }
  • 16. #include<iostream> #include"count.h" usingnamespace::std; friendvoidStillWrong() { Count C; C.x = 3; } voidmain() { StillWrong(); } friendFunctions #include<iostream> usingnamespacestd; #ifndefCount_H #defineCount_H classCount { public: friendvoidPlay (Count &C); Count(): x(0) {}; voidprint()const{cout << x << endl;}; private: intx; }; voidPlay(Count &C) { C.x = 3; } #endif Compiler error we write the “friend” key word in the function defintion!
  • 18. friend Classes •Properties of friendship –Granted not taken •class B is a friend of class A –class A must explicitly declare class B as friend –Not symmetric •class B friend of class A –class A not necessarily friend of class B! –Not transitive •A friend of B •B friend of C –A not necessarily friend of C!
  • 19. friendClasses #include<iostream> #include"_2ndClass.h" usingnamespacestd; class_1stClass { public: friendclass_2nClass; // declaring _2ntClass // as friend to _1stClass private: intx; }; #include<iostream> usingnamespacestd; #ifndef_2ndClass_h #define_2ndClass_h class_2ndClass { public: private: intx; }; #endif In _2ndClass header In _1stClass header #include<iostream> usingnamespacestd; class_1stClass { public: friendclass_2nClass; private: constintx; }; class_2ndClass { public: voidPlayWith_1stClass(_1stClass C1); private: inty; }; void_2ndClass::PlayWith_1stClass(_1stClass C1) { y = C1.x; } Now it’s all okay
  • 21. thisKeyword •“this” pointer –Represent the address memory of the object –Its values is always the memory address of the object –Can be used •Explicitly implicitly –What’s used for? •Can be used to check if a parameter passed to a member function of an object is the object itself •Cascading –Multiple function invoked in the same statement
  • 22. thisKeyword #include<iostream> usingnamespacestd; classTest { public: Test():x(){}; voidChange(int); voidprint() const; private: intx; }; voidTest::print() const { cout << x << endl; cout << this->x << endl; cout << (*this).x << endl; } voidTest::Change (intnewValue) { x = newValue; } #include<iostream> #include“Test.h" usingnamespacestd; voidmain() { Test T; T.print(); T.Change(6); T.print(); } 0 0 0 6 6 6 Press any key to continue
  • 23. thisKeyword #include<iostream> usingnamespacestd; classTest { public: Test():x(){}; voidChange(int); voidprint() const; private: intx; }; voidTest::print() const { cout << x << endl; cout << this->x << endl; cout << *this.x << endl; } voidTest::Change (intnewValue) { x = newValue; } *this.x != (*this).x because the (.) has higher precedence than (*) So,Compiler error!
  • 24. thisKeyword #include<iostream> usingnamespacestd; classTest { public: Test():x(){}; voidIsSame(Test &Tempo); voidprint() const; private: intx; }; voidTest::print() const { cout << x << endl; } voidTest::IsSame (Test &Tempo) { if(this== &Tempo) { cout << "References are the same"<< endl; } } 0 References are the same Press any key to continue #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T; Test *Tptr = &T; T.print(); Tptr->IsSame(T); }
  • 25. thisKeyword #include<iostream> usingnamespacestd; classTest { public: Test():x(){}; voidIsSame(Test &Tempo); voidprint() const; private: intx; }; voidTest::print() const { cout << x << endl; } voidTest::IsSame (Test Tempo) { if(this== &Tempo) { cout << "References are the same"<< endl; } } 0 Press any key to continue #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T; Test *Tptr = &T; T.print(); Tptr->IsSame(T); } Cause it’s passed by value not reference
  • 26. thisKeyword #include<iostream> usingnamespacestd; classTest { public: Test():x(){}; voidIsSame(Test &Tempo); voidprint() const; private: intx; }; voidTest::print() const { cout << x << endl; } voidTest::IsSame (Test &Tempo) { if(this== &Tempo) { cout << "References are the same"<< endl; } } 0 References are the same Press any key to continue #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T; Test *Tptr = &T; T.print(); T.IsSame(*Tptr); }
  • 27. thisKeyword classTime {public: Time(); Time &SetTime(int,int,int); // set functions Time &SetHour(int); Time &SetMinute(int); Time &SetSecond(int); intGetHour(); // get functions intGetMinute(); intGetSecond(); voidPrintTime(); private: inthour;intminute;intsecond; }; Time::Time() {hour = minute = second = 0; }; Time &Time::SetTime(intxhour,intxminute, intxsecond) {SetHour(xhour);SetMinute(xminute);SetSecond(xsecond); return*this;// enabling cascading }; Time &Time::SetHour(inth) { hour = (h>=0 && h<24)? h: 0; return*this;// enabling cascading }; Time &Time::SetMinute(intm) { minute = (m>=0 && m<60)? m: 0; return*this;// enabling cascading }; Time &Time::SetSecond(ints) { second = (s>=0 && s<60)? s: 0; return*this;// enabling cascading }; intTime::GetHour() {returnhour;}; intTime::GetMinute() {returnminute;}; intTime::GetSecond() {returnsecond;}; voidTime::PrintTime() {cout << hour << ":"<< minute << ":"<< second << endl; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Time T; //cascade member calls T.SetHour(12).SetMinute(5).SetSecond(2); T.PrintTime(); }
  • 29. static Class Members •Static members variables are shared among all instances of class –Keeps track of how many objects have been created •Incrementing with each constructing •Decrementing with each destructing –Must be initialized •Only once •Out side the class –Can be •public, private or protected
  • 30. static Class Members •Accessible through public member function or friends –Public static variables •When no object of class exists –Private static variables •When no object of class exists •Can be accessed via public static member functions •Can’t access non-static data or functions, why? •No thispointer for staticfunctions, why?
  • 31. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << SVariable << endl;SVariable--;}; private: staticintSVariable; }; // initialize just once outside the scope of the class intTest::SVariable = 5; voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T; } 5 6 Press any key to continue
  • 32. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << SVariable << endl;--SVariable;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T; cout << T.SVariable<<endl; } 5 6 6 Press any key to continue
  • 33. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << "const "<< SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl;SVariable- -;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { { Test T; cout << T.SVariable << endl; } cout << Test::SVariable << endl; } const 5 6 dest 6 5 Press any key to continue
  • 34. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << "const "<< SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl;SVariable- -;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { { Test T[5]; cout << Test::SVariable << endl; } cout << Test::SVariable << endl; } const 5 const 6 const 7 const 8 const 9 10 dest 10 dest 9 dest 8 dest 7 dest 6 5 Press any key to continue
  • 35. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << "const "<< SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl;SVariable- -;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { { Test *T = newTest[5]; cout << Test::SVariable << endl; } cout << Test::SVariable << endl; } const 5 const 6 const 7 const 8 const 9 10 10 Press any key to continue
  • 36. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << "const "<< SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl;SVariable- -;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { { Test *T = newTest[5]; cout << Test::SVariable << endl; delete[] T; } cout << Test::SVariable << endl; cout << Test::SVariable << endl; } const 5 const 6 const 7 const 8 const 9 10 dest 10 dest 9 dest 8 dest 7 dest 6 5 5 Press any key to continue
  • 37. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {cout << "const "<< SVariable << endl; SVariable++;}; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl;SVariable- -;}; staticintSVariable; private: }; intTest::SVariable = 5;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { { Test *T = newTest[5]; cout << Test::SVariable << endl; } cout << Test::SVariable << endl; delete[] T; cout << Test::SVariable << endl; } Compile error. Undeclared identifier T We did allocate memory and we have never been de-allocated it!
  • 38. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T1; Test T2; } const 1 const 2 dest 1 dest 0 Press any key to continue
  • 39. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test *T1; Test *T2; } Press any key to continue
  • 40. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1; Test *T2; //cout << T1->SGet() << endl; } const 1 dest 0 Press any key to continue
  • 41. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = &TSource; Test *T2; } const 1 dest 0 Press any key to continue
  • 42. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; } const 1 const 2 dest 1 Press any key to continue
  • 43. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; cout << T1->SGet() << endl; } const 1 const 2 2 dest 1 Press any key to continue
  • 44. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; cout << Test::SGet() << endl; } const 1 const 2 2 dest 1 Press any key to continue
  • 45. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; deleteT1; cout << Test::SGet() << endl; } const 1 const 2 dest 1 1 dest 0 Press any key to continue
  • 46. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; deleteT1; cout << T1->SGet() << endl; } const 1 const 2 dest 1 1 dest 0 Press any key to continue
  • 47. static Class Members #include<iostream> usingnamespacestd; classTest { public: Test() {++SVariable; cout << "const "<< SVariable << endl; }; voidprint() const; ~Test() {--SVariable; cout << "dest "<< SVariable << endl; }; staticintSGet();// static member function private: staticintSVariable;// static date member }; intTest::SVariable = 0;// initialize just once outside the scope of the class voidTest::print() const {cout << SVariable << endl;} intTest::SGet() { returnSVariable; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test TSource; Test *T1 = newTest; Test *T2; delete[]T1; cout << T1->SGet() << endl; } Runtime error coz of [] not compiler error for sure!
  • 48. static Class Members #include <iostream> using namespace::std; class TestStaticClass { public: static inti; static void StaticPublicMethodTest() { cout<< "You called a static method!" << endl; } }; intTestStaticClass::i= 0; void main() { TestStaticClassT; T.StaticPublicMethodTest(); TestStaticClass::StaticPublicMethodTest(); system("pause"); } You called a static method! You called a static method! Press any key to continue
  • 49. static Class Members #include <iostream> using namespace::std; class TestStaticClass { public: void GetMyName() { cout<< "You are in "TestStaticClass" class" << endl; } static void StaticPublicMethodTest() { cout<< "You called a static method!" << endl; } }; void main() { TestStaticClassT; T.GetMyName(); TestStaticClass::GetMyName(); system("pause"); } Compiler error!, TestStaticClass::GetMyName();is not static!
  • 50. static Class Members #include <iostream> using namespace::std; class TestStaticClass { public: void GetMyName() { cout<< "You are in "TestStaticClass" class" << endl; } static void StaticPublicMethodTest() { cout<< "You called a static method!" << endl; } }; void main() { TestStaticClassT; T.GetMyName(); system("pause"); } You are in "TestStaticClass" class Press any key to continue
  • 51. static Class Members #include <iostream> using namespace::std; class TestStaticClass { public: void GetMyName() { cout<< "You are in "TestStaticClass" class" << endl; StaticPublicMethodTest(); } static void StaticPublicMethodTest() { cout<< "You called a static method!" << endl; } }; void main() { TestStaticClassT; T.GetMyName(); system("pause"); } You are in "TestStaticClass" class You called a static method! Press any key to continue class TestClass { public: void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; } }; void main() { TestClassT; T.PublicNonStaticMethodTest(); system("pause"); } You called a non static method! You called a static method! Press any key to continue
  • 52. static Class Members class TestClass { public: intiNonStatic; static intiStatic; void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; iStatic= 5; } }; intTestClass::iStatic= 0; void main() { TestClassT; T.PublicNonStaticMethodTest(); cout<< TestClass::iStatic<< endl; system("pause"); } You called a non static method! You called a static method! 5 Press any key to continue class TestClass { public: intiNonStatic; static intiStatic; void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; iStatic= 5; iNonStatic= 5; } }; intTestClass::iStatic= 0; void main() { TestClassT; T.PublicNonStaticMethodTest(); cout<< TestClass::iStatic<< endl; cout<< T.iNonStatic<< endl; system("pause"); } Compile error iNonStatic= 5; In “PublicStaticMethodTest” Static method!
  • 53. static Class Members class TestClass { public: intiNonStatic; static intiStatic; void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; iNonStatic= 5; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; iStatic= 5; } }; intTestClass::iStatic= 0; void main() { TestClassT; T.PublicNonStaticMethodTest(); cout<< TestClass::iStatic<< endl; cout<< T.iNonStatic<< endl; system("pause"); } You called a non static method! You called a static method! 5 5 Press any key to continue class TestClass { public: intiNonStatic; static intiStatic; void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; iNonStatic= 5; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; this.iStatic= 5; } }; intTestClass::iStatic= 0; void main() { TestClassT; T.PublicNonStaticMethodTest(); cout<< TestClass::iStatic<< endl; cout<< T.iNonStatic<< endl; system("pause"); } This can’t be used in a static method! It’s logically wrong!
  • 55. static Class Members class TestClass { public: intiNonStatic; static intiStatic; void PublicNonStaticMethodTest() { cout<< "You called a non static method!" << endl; this.iNonStatic= 5; PublicStaticMethodTest(); } static void PublicStaticMethodTest() { cout<< "You called a static method!" << endl; iStatic= 5; } }; intTestClass::iStatic= 0; void main() { TestClassT; T.PublicNonStaticMethodTest(); cout<< TestClass::iStatic<< endl; cout<< T.iNonStatic<< endl; system("pause"); } Compiler error
  • 58. Constructors and Destructors #include <iostream> using namespace::std; class TestClass { public: char* _name; TestClass(char *name) { this->_name = name; cout<< "Constructor for" << _name << endl; } ~TestClass() { cout<< "Destructor for" << _name << endl; } }; void main() { TestClassT1("T1"); { TestClassT2("T2"); static TestClassTStaticInMainInnerScope("TStaticInMainInnerScope"); } static TestClassTStaticInMainOuterScope("TStaticInMainOuterScope"); TestClassT4("T4"); } TestClassTGlobal("TGlobal"); static TestClassTStaticGlobal("TStaticGlobal"); Constructor forTGlobal Constructor forTStaticGlobal Constructor forT1 Constructor forT2 Constructor forTStaticInMainInnerScope Destructor forT2 Constructor forTStaticInMainOuterScope Constructor forT4 Destructor forT4 Destructor forT1 Destructor forTStaticInMainOuterScope Destructor forTStaticInMainInnerScope Destructor forTStaticGlobal Destructor forTGlobal Press any key to continue
  • 59. Quiz
  • 60. Quiz #1 #include<iostream> #include"date.h" usingnamespacestd; #ifndefemployee_h #defineemployee_h classemployee { public: employee(); employee(char*First, char*Last, constdate& d1, constdate& d2); voidprint()const; ~employee(); private: charFirstName [20]; charLastName [20]; constdate hiredate; constdate birthdate; }; employee::employee(char*First, char*Last,constdate& d1, constdate& d2):birthdate(d1), hiredate(d2) { intLength = strlen(First); strncpy(FirstName,First,20); FirstName[Length]='0'; strncpy(LastName,Last,20); LastName[Length]='0'; cout<<"constructor runs for employee:"<<FirstName<<' '<< LastName<<endl; // ' ' space char;) } voidemployee::print() const { cout << "Employee: "<< FirstName << ' '<< LastName << endl; cout << "printing dates for this employee"<< endl; birthdate.print(); hiredate.print(); cout << "________________"<< endl; } employee::~employee() { cout << "destructor runs for employee class, for "; print(); } #endif
  • 61. Quiz #1, What’s the Output? #include<iostream> #include"employee.h" #include"date.h" usingnamespacestd; voidmain() { date Birth1 (8,8,1990); date Hire1 (4,4,2010); date Birth2 (10,10,1990); date Hire2 (5,5,2010); employee manager1 ("mee", "loo", Birth1, Hire1 ); employee manager2 ("zee", "HooHoo", Birth2, Hire2 ); manager1.print(); manager2.print(); } #include<iostream> usingnamespacestd; #ifndefdate_h #definedate_h classdate { public: date(int= 1, int= 1, int= 1990); voidprint()const; ~date(); private: intday, month, year; }; date::date(intd, intm, inty) {day = d; month = m, year = y; cout << "Constructor runs for date class “;print();} voiddate::print() const {cout << day << "/"<< month << "/"<< year << endl; } date::~date() {cout << "destructor runs for date class, which date is:"<<endl; print(); } #endif
  • 62. Quiz #1 destructor runs for employee class, for Employee: zee HooHoo printing dates for this employee 10/10/1990 5/5/2010 ________________ destructor runs for date class, which date is: 5/5/2010 destructor runs for date class, which date is: 10/10/1990 destructor runs for employee class, for Employee: mee Hee printing dates for this employee 8/8/1990 4/4/2010 ________________ destructor runs for date class, which date is: 4/4/2010 destructor runs for date class, which date is: 8/8/1990 destructor runs for date class, which date is: 5/5/2010 destructor runs for date class, which date is: 10/10/1990 destructor runs for date class, which date is: 4/4/2010 destructor runs for date class, which date is: 8/8/1990 Constructor runs for date class 8/8/1990 Constructor runs for date class 4/4/2010 Constructor runs for date class 10/10/1990 Constructor runs for date class 5/5/2010 constructor runs for employee:mee Hee constructor runs for employee:zee HooHoo Employee: mee Hee printing dates for this employee 8/8/1990 4/4/2010 ________________ Employee: zee HooHoo printing dates for this employee 10/10/1990 5/5/2010 ________________
  • 63. Quiz #2, What’s the Output? #include<iostream> usingnamespacestd; classTest { public: Test() { cout << "const "<< SVariable << endl; SVariable++; }; voidprint() const; ~Test() {cout << "dest "<< SVariable << endl; SVariable--; }; staticintSVariable; private: }; intTest::SVariable = 5; voidTest::print() const { cout << SVariable << endl; } #include<iostream> #include"MyFile.h" usingnamespacestd; voidmain() { Test T1; { Test T2[5]; Test TTemp; cout << TTemp.SVariable << endl; } cout << Test::SVariable << endl; Test *T3 = &T1; staticTest T4; cout << Test::SVariable << endl; Test* &T5 = T3; cout << Test::SVariable << endl; } const 5 const 6 const 7 const 8 const 9 const 10 const 11 12 dest 12 dest 11 dest 10 dest 9 dest 8 dest 7 6 const 6 7 7 dest 7 dest 6