Solved

Inheritance

Posted on 1998-12-15
4
257 Views
Last Modified: 2010-04-02
1)if Class A is base class for Class B then the private data members of base class are inherited or not?
I think they are inherited but we can't access them.

2)Protected data members of base class can be accessed by object of a derived class or only public member function of derived class.
0
Comment
Question by:manjucee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1180255
1)
Private members of the base class are part of the derived class object - however, as you had specified, they cannot be accessed by derived class member functions.
2)
Protected members of base class may become protected or private in the derived class, depending on the type of derivation - and as such can be accessed only by member functions of the derived class.
I am providing this answer, not taking into consideration friend classes and functions
thanks
pagladasu
0
 

Author Comment

by:manjucee
ID: 1180256
Hi pagladasu,
         Thanks for clarifying the doubts.
Thanks
Manju
0
 

Author Comment

by:manjucee
ID: 1180257
Hi pagladasu,
                        if i inherit baseclass privately  then also the private data members are inherited and only thing is that i can't access them in derived class. (Y/N)
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1180258
You are welcome. Just for curiosity - are you new to C++. If you face any problems, feel free to post it at my mail:espical@hotmail.com
pagladasu
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 126
c++ substatte a varabe for a string in a LPCTSTR statment 8 101
Create a path if not exists 7 126
c++, dynamic object by json 1 65
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question