cpp unit 2
cpp unit 2
SYNTAX :
SYNTAX USING FUNCTION OUTSIDE THE
CLASS :
FUNCTION:
The definition of a function in programming refers to providing the
actual implementation or code body of a function. It specifies what the
function does when it is called. In languages like C++, a function
declaration merely declares the function's name, return type, and
parameters without providing its actual implementation. The definition,
on the other hand, includes the complete function body.
TYPES OF THE FUNCTIONS
Without argument without return value
Definition:
Constructors are defined like regular functions, but they are preceded
by the class name and use the scope resolution operator (::).
The body of the constructor contains initialization code.
Declaration:
Destructors have the same name as the class, preceded by a tilde
(~), and they also have no return type.
Destructors cannot have parameters.
Definition:
Destructors are defined similarly to constructors but with the
tilde (~) preceding the class name.
The destructor typically contains cleanup code, such as releasing
resources acquired by the class.
Destructors do not take parameters, and there can only be one
destructor per class.
Destructors are called automatically when objects are destroyed,
either when they go out of scope (for automatic variables) or
when delete is called on dynamically allocated objects.