Sunday, March 20, 2022

inheritance

 #include <iostream>

using namespace std;
class base
{
protected:
    int num1, num2;

public:
    base() {}
    base(int num1, int num2)
    {
        this->num1 = num1;
        this->num2 = num2;
    }
    virtual void printdata()
    {
        cout << num1 << " and " << num2 << endl;
    }
};
class child : virtual public base
{


    int num3;

public:
    child() {}
    child(int num3, int num2, int num1) : base(num1, num2)
    {
        this->num3 = num3;
    }
    void printdata()
    {
        cout << "num3 and base class nums are " << num3 << " " << num1 << " " << num2 << endl;
    }
};
class derived : virtual public base
{
};
class new4 : public child, public derived
{
};
int main()
{
    base *ptr, obj1(2, 3);
    ptr = &obj1;
    ptr->printdata();

    child obj(4, 5, 6);
    ptr = &obj;
    ptr->printdata();
    return 0;
}

No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts