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

  • Tarun Chauhan
    Tarun Chauhan
    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.
  • Tarun Chauhan
    Tarun Chauhan
    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.

    and yes even after correction the code is not working,it is showing error like "getdata() was not declared in this scope"....
  • Tarun Chauhan
    Tarun Chauhan
    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.

You are reading an archived discussion.

Related Posts

The 19th Question of the CE Grand Quiz Contest is as follows - [Worth 5 CE Coins] The local milk shop would be closed for the next few days. Knowing...
I am currently pursuing 4-1 in some engg college of AP..The problem is , I took .Net as my platform for my Miniproject.Now,I am a little bit confused as to...
I am planning to develop a Pure Sine Wave inveter 500W. Requesting your help to fulfill the same. Thanks in advance...
Name: Harish Kotra Engineering Trade: Computer Science & Engineering Location: Andhra Pradesh Occupation: Student Work Experience: None for now. Hobbies & Interests: I am an Android Enthusiast and a passionate...
Wishing a very, very happy birthday to CEans Mohit & Manish. 😁 Be proud to be a november born! 😉 Many Many Happy Returns of the Day! 🎉