Ad Code

Responsive Advertisement

C++ class attributes function - Learn CPP

C++ class attributes function - Learn CPP, Class in the C++ programming language is a new type that is defined by a class. This type can contain functions, variables, or arrays, and the type is defined by the class. It is very similar to the type defined by struct, but the main difference between class and struct is that a struct can access anything in it directly while in a class it is specified Whether or not the objects that are defined in it can be accessed directly.

The process of defining the way in which the objects in the class can be accessed enables us to apply all of the accepted principles of object-oriented programming (OOP).


C++ class attributes function - Learn CPP



How to define a class in C++ programming language


To define a new class in the C++ programming language, we write the word “class” and give it a specific name, after which parentheses are opened to define the beginning and end of the class.


The concept of Attributes in C++


The properties are the set of variables, arrays, and objects that are defined within the class, and which will have a special copy of any object we create from it. Specifiers) which are:


public


Used to specify that properties placed in the class can be accessed from anywhere.


private


Used to specify that properties defined in the class cannot be accessed from outside the class.


protected


Used to specify that objects in the class are accessible when applying the concept of inheritance.


Class Concepts


Constructor


It is a distinct function that is called automatically when creating an object from the class, and this function makes the user able to pass the initial values of the object directly when defining it.


Destructor


A distinct function is called automatically when an object is erased.


Friend Function


A function that can access properties of an object even if an object is in the class of its type (private) or (protected).