WINSEM2019-20 CSE1002 LO VL2019205005576 Reference Material I 04-Feb-2020 Classes
WINSEM2019-20 CSE1002 LO VL2019205005576 Reference Material I 04-Feb-2020 Classes
WINSEM2019-20 CSE1002 LO VL2019205005576 Reference Material I 04-Feb-2020 Classes
Classes
• Classes are created using the keyword class.
access-specifier:
access-specifier:
// ...
access-specifier:
} object-list;
Classes
The object-list is optional. If present, it declares objects of
the class. Here, access-specifier is one of these three C++
keywords:
public
private
protected
• By default, functions and data declared within a class are
private to that class and may be accessed only by other
members of the class.
• The public access specifier allows functions or data to be
accessible to other parts of your program.
• The protected access specifier is needed only when
inheritance is involved.
Classes
• You may change access specifications as often as you like
within a class declaration.
• Functions that are declared within a class are called
member functions.
• Member functions may access any element of the class of
which they are a part.
• This includes all private elements. Variables that are
elements of a class are called member variables or data
members. Collectively, any element of a class can be
referred to as a member of that class.
Class Methods
• Methods are functions that belongs to the class.
• There are two ways to define functions that belongs
to a class:
Inside class definition
Outside class definition