|
|
C++ Definitions:
based on "C Programming" K.N. King, Norton, 1995.
Defining a CLASS in C++ is much like defining a structure,
for example:
class Fraction {
int numerator
};int denominator
numerator and denominator are said to be data members.
Note use of Initial case for ClassName (just a convention,
not a requirement of C++). Now we are free to use the new
class (type) called Fraction:
Fraction f1, f2;
f1 and f2 are instancesof the Fraction class. An instance
of any class is also known as an object.
Unlike structures we cannotaccess these elements with
f1.numerator
bottom = f2.denominator// this is illegal, private member
// again illegal
To be accessible the private data members need "public"
operators. By default data members are private.
Ignoring the possible existence of public data members, let
us consider now how public access functions are declared.
|
|