Lecture 4-7
Lecture 4-7
Classes
• Class declaration:
describes new type that links code and data.
describes scope of its members.
• Class function definitions: describes how the class functions
are implemented.
• Class is the logical abstraction.
General form of Class declaration
Difference between Structure and
Class
• By default, members of class are private, while, by
default, members of structure are public.
• Encapsulation
Creating Objects:
item x;
int main()
{
account obj1,obj2;
account::display(); //accessing static function
account obj3;
account::display();
return 0;
}
Output:
The value of count= 51
The value of count= 52
Restrictions on Static Member
Function
• They may directly refer to the other static members of
the class.
• A static member function does not have a this pointer.
• There cannot be a static and non-static version of the
same function.
• A static member function may not be virtual.
• They cannot be declared as const.
Use:
To “Preinitialize” private static data before any object is
actually created.