The Private Member In Derived Class

The Private Member In Derived Class




πŸ›‘ πŸ‘‰πŸ»πŸ‘‰πŸ»πŸ‘‰πŸ» INFORMATION AVAILABLE CLICK HEREπŸ‘ˆπŸ»πŸ‘ˆπŸ»πŸ‘ˆπŸ»





















































Because it accesses i via the method set : such method is protected hence accessible from Derived .

while we didn't allocate memory to i and didn't create an object of class Base
how it can be done?
Sergey Alexandrovich Kryukov

10-Jul-11 17:22pm


What do you mean allocate? -- it's not a pointer! Look, I see you completely lost in basics of programming. You need to step back and really understand variables, parameters, pointers, etc. before you go into OOP. This is what stops you, not classes.
--SA
You've just lost 1000 C++ points, with this comment. Please read a good book on C++ and OOP (if you create an object of class Derived , you get, for free, all the members, of class Base , because Derives is Base too. That's one of the reason inheritance is made for).
Sergey Alexandrovich Kryukov

10-Jul-11 17:21pm


Correct, a 5. OP is totally lost (see my answer).
--SA

This is not true: "private members doesn't Derive". This is not even false, just makes no sense. :-)
A member can not "derive", only a type can. All members are inherited, no exclusions.

β€”SA

Espen Harlinn

10-Jul-11 17:22pm


Sergey Alexandrovich Kryukov

10-Jul-11 17:29pm


so,how change method of Derived class works?
OriginalGriff

11-Jul-11 2:51am


Because the protected member function "Set" accesses the private member - which it is allowed to do, being a part of the "Base" class. The derived class cannot access private "Base" members except via Protected or public methods. Even then it has no direct access, it can only provide a parameter value which the protected function then uses as it will.
Christian Graus

10-Jul-11 17:24pm


Your protected code accesses your private member. It works as it should. What you want to do, is not clear, so 'works' is not defined.
Ouch, you just earned yourself a thorough whip-lashing with that suggestion!
;-p
Espen Harlinn

11-Jul-11 12:49pm


Possibly - I did mention something about the dirty tricks department :)

Treat my content as plain text, not as HTML


I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the CodeProject newsletters


When answering a question please:

Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.

Let's work to help developers, not make them feel stupid.


Advertise
Privacy
Cookies
Terms of Use
Last Updated 10 Jul 2011


Copyright Β© CodeProject , 1999-2021
All Rights Reserved.

Web01
2.8.20210901.1


CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Stack Overflow for Teams
– Collaborate and share knowledge with a private group.



Create a free Team
What is Teams?


Asked
6 years, 11 months ago


Active
6 years, 11 months ago


20.3k 8 8 gold badges 60 60 silver badges 81 81 bronze badges


99 3 3 silver badges 11 11 bronze badges


195k 20 20 gold badges 278 278 silver badges 476 476 bronze badges


53.9k 34 34 gold badges 123 123 silver badges 194 194 bronze badges

Minsk, Belarus 10k+ Artificial Intelligence Public
We set out to change the way the world interacts with data - starting with state of the art AI and an unapologetically bold team.
c# javascript .net-core .net node.js angularjs sql

Stack Overflow

Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness


Products

Teams
Talent
Advertising
Enterprise



Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy



Stack Exchange Network

Technology
Life / Arts
Culture / Recreation
Science
Other




Accept all cookies



Customize settings


I used to see everywhere that private members of base class are never inherited in derived class, no matter how you inherit the base class (private or protected or public).
But below question has really confused me up. I don't know why the output of this program is 80. It should be 1 byte (which is the size of an empty class in C++) because private members are never inherited.
This is mostly a problem of semantics and what different people refer to with inherited . When a type D inherits from a type B , each D object contains a full B object. From that point of view all of the members are there (and some people call this inherited ). On the other hand, those members are not accessible from the members of D , and from that point of view the members are as if they were not there (and some people call this not inherited ).
Private members of a base (no matter what accesibility) are not accessible from the derived types (assuming no friendship relationship), but they are there, an object of the derived type contains an object of the base type.
Yes, derived classes inherit members from all of their base classes.
The keywords private, public and protected affect only the accessibility of the items they are applied to. If something is not accessible in a particular context and you try to use it, the compiler will give you an error.

By clicking β€œPost Your Answer”, you agree to our terms of service , privacy policy and cookie policy

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo Β© 2021 Stack Exchange Inc; user contributions licensed under cc by-sa . revΒ 2021.9.9.40165


By clicking β€œAccept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .


https://www.codeproject.com/questions/223578/access-private-members-in-derived-class
https://stackoverflow.com/questions/26161346/are-private-members-of-base-class-always-inherited-in-derived-class-in-c
Bbw Older Kinky Fuck Bbc Tube
Xnxx Com Sissy
The Helpful Fox Senko San Porn
[Solved] access private members in derived class - CodeProject
How to make a derived class access the private member data?
The private members of the base class are visible in ...
inheritance - Are private members inherited in C#? - Stack ...
C++ - Accessing protected/private members of a base class
Accessing protected members in a C++ derived class
C++ Tutorial: Private Inheritance - 2020
c++ - How is this private data member of a base class ...
Which access type data gets derived as private member in ...
The Private Member In Derived Class


Report Page