OOP with C++ and ChatGPT | Lecture 2 Defining Declaring and Access Specifiers |

Опубликовано: 01 Май 2026
на канале: TechByAbdullah
34
0

Defining and Declaring in C++
Defining

Definition of a variable or a function means providing the actual implementation or initializing it.
In the case of a variable, defining it means allocating memory and optionally assigning a value.
For a function, defining it means providing the body of the function, where the actual logic is written.
Declaring

Declaration of a variable or a function means informing the compiler about its type and name, without allocating memory or providing the implementation.
For variables, it tells the compiler that a variable of a certain type exists.
For functions, it specifies the function's name, return type, and parameters, without including the body of the function.
Access Specifiers in C++
Access specifiers in C++ determine the accessibility of class members. The main access specifiers are:

Public

Members declared as public are accessible from outside the class.
They can be accessed directly by any other code.
Protected

Members declared as protected are accessible within the class itself and by derived classes.
They are not accessible from outside the class, except through inheritance.
Private

Members declared as private are accessible only within the class itself.
They cannot be accessed directly from outside the class, ensuring encapsulation and data hiding.