www.easyCPlusPlus.com

Easy C++

www.easyCPlusPlus.com

C++ Tutorial - Lesson 9: Introduction to Classes

Introduction

by John Kopp

Support this site at no cost to you

So far, the lessons in this tutorial have focused on presenting the basic syntax of C++. You've learned how to declare and use variables, control the flow of execution with loops and conditional processing, some basic ways to handle input and output and about pointers and arrays. This lesson introduces classes and objects. The use of objects in C++ defines the way programs are designed and written. Classes are a software construct that can be used to emulate a real world object. Classes encapsulate data and abilities. For instance, a software model of a car, a car "class", might contain data about the type of car and abilities such as accelerate or decelerate. A class is a programmer defined data type that has data, its members, and abilities, its methods. An object is a particular instance of a class. This is best understood by an analogy with a built in data type such as int.

int x;

Declares x to be a variable of type int.

Car impala;

Declares impala to be an object of class Car.

Please Note: The concepts introduced in this lesson will be revisited and explained in detail in later lessons.

Previous Page       Next Page