by Dinesh Thakur Category: Classes in C++

The member functions are created and placed in the memory space only once when they are defined as a part of a class specification. Since· all the objects belonging to that class use the same member functions, no separate space is allocated for member functions when the objects are created. For each object, memory is allocated only for member data. Separate memory locations for the objects are essential since the member variables hold different data values for different objects.

 
by Dinesh Thakur Category: Classes in C++

Member of a class can be accessed only through the object of a class. The members are accessed as follows:

 
by Dinesh Thakur Category: Classes in C++

The difference between a structure and a class is that, in a class, the member data or functions are private by default whereas, in a structure, they are public by default. The following segment

 
by Dinesh Thakur Category: Classes in C++

The const qualifier is used with the variables of basic data types to prevent them from being modified by the function. In a similar way, const qualifier can also be applied to member functions, member function arguments and the objects of a class.



 
by Dinesh Thakur Category: Classes in C++

A function can also return objects either by value or by reference. When an object is returned by value from a function, a temporary object is created within the function, which holds the return value. This value is further assigned to another object in the calling function.

 
by Dinesh Thakur Category: Classes in C++

The objects of a class can be passed as arguments to member functions as well as nonmember functions either by value or by reference. When an object is passed by value, a copy of the actual object is created inside the function. This copy is destroyed when the function terminates. Moreover, any changes made to the copy of the object inside the function are not reflected in the actual object. On the other hand, in pass by reference, only a reference to that object (not the entire object) is passed to the function. Thus, the changes made to the object within the function are also reflected in the actual object.

 
by Dinesh Thakur Category: Classes in C++

Like array of other user-defined data types, an array of type class can also be created. The array of type class contains the objects of the class as its individual elements. Thus, an array of a class type is also known as an array of objects. An array of objects is declared in the same way as an array of any built-in data type.



 
by Dinesh Thakur Category: Classes in C++

Arrays can be declared as the members of a class. The arrays can be declared as private, public or protected members of the class.

 
by Dinesh Thakur Category: Classes in C++

The members of a class can be directly accessed inside the class using their names. However, accessing a member outside the class depends on its access specifier. The access specifier not only determines the part of the program where the member is accessible, but also how it is accessible in the program.

 
by Dinesh Thakur Category: Classes in C++

Once a class is defined, it can be used to create variables of its type known as objects. The relation between an object and a class is the same as that of a variable and its data type.



 
by Dinesh Thakur Category: Classes in C++

Member functions of a class can be defined either outside the class definition or inside the class definition. In both the cases, the function body remains the same, however, the function header is different.

 
by Dinesh Thakur Category: Classes in C++

A class is a user-defined data type that binds data and the functions that operate on the data together in a single unit. Like other user-defined data types, it also needs to be defined before using its objects in the program. A class definition specifies a new data type that can be treated as a built-in data type.



 
by Dinesh Thakur Category: Classes in C++

Polymorphism (a Greek word meaning having multiple forms) is the ability of an entity such as a function or a message to be processed in more than one form. It can also be defined as the property of an object belonging to a same or different class to respond to the same message or function in a different way. For example, if a message change_gear is passed to all the vehicles then the automobiles will respond to the message appropriately however, the pulled vehicles will not respond. The concept of polymorphism plays an important role in OOP as it allows an entity to be represented in various forms.

 
by Dinesh Thakur Category: Classes in C++

Abstraction is a mechanism to' hide irrelevant details and represent only the essential features so that one can focus on important things at a time; It allows managing complex systems by concentrating on the essential features only. For example, while driving a car, a driver only knows the essential features to drive a car such as how to use clutch, brake, accelerator, gears, steering, etc., and least bothers about the internal details of the car like motor, engine, wiring, etc.

 
by Dinesh Thakur Category: Classes in C++

A feature of some programming languages in which the same 0PERATORmay be used on different data types with different, but analogous, results. For example most languages permit the same operator + to add either INTEGER or FLOATING-POINT numbers, and many further allow it to be used to CONCATENATE strings, so that 'rag' + 'mop' produces 'ragmop'. A few languages, including C++, allow the programmer to create new operator overloading.



 

Page 1 of 6



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles