Inheritance Access Issue

Am geting the following error, "Use of deleted function ‘Derived::Derived’" while executing the below code related to Inheritance. Also in the note it says, "Derived::Derived() is implicitly deleted because
the default definition would be ill informed". Can someone help me in fixing this:

#include <iostream>

//BASE CLASS
class Base
{
public:
    int a;
    
    void display()
    {
        std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl;
    }
    
    //constructor
    Base(int la, int lb, int lc) : a {la}, b {lb}, c {lc}
    {
        
    }

protected:
    int b;

private:
    int c;
};

//DERIVED CLASS
class Derived : public Base
{
    //a from Base is Public
    //b from Base is Protected
    //c from Base has No access
    
public:
    void access_base_members()
    {
        a = 100;    //OK since a is Public in parent
        b = 200;    //OK since b is Protected type in Parent. So derived CLASS will have access
        //c = 300;    //NOK since c is private in parent and hence cannot be accessed
    }
};


int main()
{
    std::cout << "nBase Member access=>nn";
    
    Base base(1,2,3);
    base.a = 10; //OK
    //base.b = 20; //NOK since Protected
    //base.c = 30; //NOK since Private
    base.display();

    Derived derived;
    derived.a = 111;        //OK since public in parent
    //derived.b = 222;        //NOK since protected members cannot have direct access in OBJECTS
    //derived.c = 333;        //NOK since private
}

Source: Windows Questions C++

LEAVE A COMMENT