Posts

Showing posts with the label Object

Introduction to Classes in C++

Class : A class is an extension to the structure Data Type: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable. Classes are generally declared using the keyword class , with the following Syntax: class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names;//This is optional Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers. All is very similar to the declaration of a structure, except that we can now include also functions and members, but also this new thing called access specifier . An access specifier is one of the following three keywords: private , public or prot