CrazyEngineers
  • Tarun Chauhan
    Tarun Chauhan

    MemberNov 20, 2011

    inheritance in c++

    hello everyone!
    my question is when we inherit a base class say B privately through a derived class say D, the public and protected members of base class become private members for derived class,alright. but in such a way the public members of derived class should be able to access the public members of base class(since they are now private members for derived class) and since public members of one class can access its private members,the derived class member function should be able to access private members of base class through public members of base class,but code is not working.
    i don't where is the problem.i think the way i am calling a base class' function inside derived class' has some error.i attached the file please give your valuable comments
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Tarun Chauhan

    MemberNov 20, 2011

    hey friends i found one bug.it is with the wrong way of calling.it shouldn't include neither base class' name and nor scope resolution operator.
    i.e inside derived class' function instead of "b::getdata(a,b);" it should be simply "getdata(a,b);" to call base class' member function,as it is the way to call one class' private member by its public member function.
    one more thing,i tried to access protected member of base class b through its object in main function just to check the basics,and when found it really inaccessible simply added // to make this comment non-functional so that doesn't have any relation with asked question,please don't argue that as a bug.
    Are you sure? This action cannot be undone.
    Cancel
  • Tarun Chauhan

    MemberNov 20, 2011

    hey friends i found one bug.it is with the wrong way of calling.it shouldn't include neither base class' name and nor scope resolution operator.<br>i.e inside derived class' function instead of "b::getdata(a,b);" it should be simply "getdata(a,b);" to call base class' member function,as it is the way to call one class' private member by its public member function.<br>one more thing,i tried to access protected member of base class b through its object in main function just to check the basics,and when found it really inaccessible simply added // to make this comment non-functional so that doesn't have any relation with asked question,please don't argue that as a bug.

    and yes even after correction the code is not working,it is showing error like "getdata() was not declared in this scope"....
    Are you sure? This action cannot be undone.
    Cancel
  • Tarun Chauhan

    MemberNov 20, 2011

    ohh friends what a childish mistake i did........talking about inheritance and didn't even declared the type of inheritance while declaring derived class.now after correcting the error shown in above reply and this,the code is working...thanks for giving your valuable time for this post.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register