Sams Teach Yourself C++ in 21 Days

(singke) #1
The important idea is that you should pick one style and stay with it through each pro-
gram. Over time, your style will evolve to include not only naming conventions, but also
indentation, alignment of braces, and commenting style.

142 Day 6


It’s common for development companies to have house standards for many
style issues. This ensures that all developers can easily read one another’s
code. Unfortunately, this extends to the companies that develop operating
systems and libraries of reusable classes, which usually means that C++ pro-
grams must work with several different naming conventions at once.

NOTE

As stated before, C++ is case sensitive, so all class, function, and variable
names should follow the same pattern so that you never have to check how
to spell them—was it Rectangle, rectangle, or RECTANGLE?

CAUTION

Defining an Object ........................................................................................


After you declare a class, you can then use it as a new type to declare variables of that
type. You declare an object of your new type the same as you declare an integer variable:
unsigned int GrossWeight; // define an unsigned integer
Cat Frisky; // define a Cat
This code defines a variable called GrossWeight, whose type is an unsignedinteger. It
also defines Frisky, which is an object whose class (or type) is Cat.

Classes Versus Objects ..................................................................................


You never pet the definition of a cat; you pet individual cats. You draw a distinction
between the idea of a cat and the particular cat that right now is shedding all over your
living room. In the same way, C++ differentiates between the class Cat, which is the idea
of a cat, and each individual Catobject. Thus,Friskyis an object of type Catin the
same way that GrossWeightis a variable of type unsigned int.
An object is an individual instance of a class.

Accessing Class Members ..................................................................................


After you define an actual Catobject—for example,
Cat Frisky;
Free download pdf