Monday , 28 September 2020
Breaking News

Objects and Classes in C++

Notice: Undefined index: tie_hide_meta in /home1/adnanonl/public_html/wp-content/themes/sahifa/framework/parts/meta-post.php on line 3

Notice: Trying to access array offset on value of type null in /home1/adnanonl/public_html/wp-content/themes/sahifa/framework/parts/meta-post.php on line 3
Spread the love

OOPs. it is a paradigm of programming that is based on the concepts of object and class. First, let’s define what we mean by object and class:

Object: An autonomous entity with a specific and well-defined functionality.
Specification of the characteristics of a set of objects.
An object is an instance of a class.
The concepts presented in this section will be illustrated using an example that will be completed little by little as new concepts are introduced. Moreover, this same example is used in the sections dedicated to the treatment of exceptions and programming with threads. So, let’s prepare the way by creating a project:

Create a project (File | New | Application)
Change the name of the form (Name = PpalFrm). Place a PaintBox on the System components page that is named PaintBox, with Align = alTop. Leave space below the PaintBox to place a button.
Place a bevel of width 4 and align it on the top (Align = alTop). The idea is to delimit the lower part of the PaintBox.
Place a bit button that allows to finish the execution of the program. The button will be centered horizontally at the bottom of the form.
Save the code of the form as Ppal.cpp and the project as Example.bpr.
Create a unit (File | New | Unit). Save it with the name ObjGraf.cpp
When a unit is created in this way, two files are actually created, one with extension .cpp and another with extension .h. Thus, we have two files: ObjGraf.h, which will contain the declarations of the classes with which we are going to work, and ObjGraf.cpp, which will contain the definition (implementation of the methods) of these.

In ObjGraf.h:

// ———————————————— –

#ifndef ObjGrafH
#define ObjGrafH

// Definition of the TObjGraf class

class TObjGraf {};


// ———————————————— –
Note that the name of the class is preceded by a T, and, although it is not mandatory, it is highly recommended since it is a C ++ Builder convention that almost all class names are preceded by T.


Leave a Reply

Your email address will not be published. Required fields are marked *