Concept of Function Overriding in OOP of C++

Mannan Ul Haq
0

Function overriding is a feature in C++ that allows a derived class to provide a different implementation of a function that is already defined in its base class. It allows you to redefine the behavior of a function in the derived class, providing specialization or customization based on the derived class's specific requirements.


To override a function in C++, the following conditions must be met:


1. Inheritance: The derived class must inherit from the base class.


2. Function Signature: The function in the derived class must have the same name, return type, and parameter list (including the constness) as the function in the base class.


Example:


class Parent
{
public:

    void Print()
    {
        statements;
    }
};

class Child : public Parent
{
public:

    void Print()
    {
        statements;
    }
};

int main()
{
    Child Child_Derived;

    Child_Derived.Print();

    return 0;
}


Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !