× Home (CS 211) Notes Projects Waxman's Website

Data Types

The following are primative data types:
class1
These data types are built-in data types and can be used directly by the user to declare variables. But sometimes we need more than just simple data types, in such time we use classes.

Classes

A class is a data type that contain different parts, these parts are known as members. There are two types of members, data and function members. These members are only associated with the class. An object is an instance of a class. You have already been exposed to a class already: strings.
class2
s1 and s2 are string objects. the .size() and .substr() are member functions of the string class.

Class Layout

class3
private:
This area is for the private variables and functions. These members can only be access from within the class.
public:
This area is for the public variables and functions. These members can be access from anywhere as long as an instance of the class exist.

Constructor/Destructor

A constructor is a function that gets called when a object needs to be created. The purpose of the constructor is to initialize the data members.
A constructor is declared with the same name as the class, and with no return type.

Destructors are called automatically when an object is deleted. This happens when the object goes out of scope. If you don't define a destructor, the compiler will create one for you, which deletes each data member. You should use a destructor to delete anything that you declared dynamically, to avoid a memory leak.

Go to: RAT Class for more information on classes and specfics on RAT class.