"class sample:private demo" what is wrong in this ?

+1 vote
asked Dec 27, 2018 by (190 points)

1 Answer

+1 vote
answered Jan 4 by (830 points)
Nothing should be wrong with that code you have given. The only issue would be if you didn't have a private section in the "demo" class because there would be nothing to inherit. Other than that possibility, this is a perfectly error-free derived class definition.
commented Jan 11 by (190 points)
Of-course you are right , but i think private members are not accessed directly.
I tried this program but it is shoing errors.
commented Jan 11 by (830 points)
Oh, I see what you're saying. You're right. Because the member functions are private, they can't be called by functions outside of the class. If your other code is attempting to do this, You would need a public member function in the demo class to call the private one.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...