Differentiate between a member function and a normal function. What are narrow classes? Can instance empty class be created? Give reason.
Q.) Differentiate between a member function and a normal function. What are narrow classes? Can instance empty class be created? Give reason.
Subject: Object Oriented Programming MethodologyMember Function vs. Normal Function
Member Function:
- A member function is a function that is defined inside a class.
- It can access the private and protected data members of the class.
- It is typically used to manipulate the data members of the class.
Syntax:
class ClassName { // Data members // ... // Member functions void memberFunction() { // Function body } };
Normal Function:
- A normal function is a function that is defined outside a class.
- It cannot access the private and protected data members of a class.
- It is typically used to perform general-purpose tasks.
- Syntax:
void normalFunction() { // Function body }
Narrow Classes
- A narrow class is a class that contains only pure virtual functions.
- Pure virtual functions are functions that have no implementation in the class.
- They are declared with the
= 0
syntax. - Narrow classes are used to create abstract base classes.
- An abstract base class is a class that cannot be instantiated.
- It is used to define an interface that derived classes must implement.
Instance of Empty Class
- An instance of an empty class cannot be created.
- This is because an empty class has no data members or member functions.
- Therefore, there is no way to store any data in an instance of an empty class.
Reason:
- An empty class has no data members or member functions.
- Therefore, there is no way to store any data in an instance of an empty class.
- Consequently, an instance of an empty class cannot be created.