473,473 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page 572, C++ primer, 4th edition

In the example, d2.basemem() is error. I don't know why, basemem is
private member function in the derived class d2, but d2 can use its own
member function, no matter what type it is.

Oct 10 '06 #1
3 1565

"asdf" <li*********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
In the example, d2.basemem() is error. I don't know why, basemem is
private member function in the derived class d2, but d2 can use its own
member function, no matter what type it is.
How about posting the actual code you've got a question with? Is there some
reason you assume we all have that book?

-Howard

Oct 10 '06 #2
On 10 Oct 2006 07:56:52 -0700, "asdf" <li*********@gmail.comwrote:
>In the example, d2.basemem() is error. I don't know why, basemem is
private member function in the derived class d2, but d2 can use its own
member function, no matter what type it is.
Try to post code...

From the book, but somehow snipped:

class Base {
public:
void basemem();
protected:
int i;
};

struct Public_derived : public Base {
int use_base() {return i;}
};

struct Private_derived : private Base {
int use_base() {return i;}
};

And the lines the OP was refering to:

Base b;
Public_derived d1;
Private_derived d2;

b.basemem(); // ok...
d1.basemem(); // ok...
d2.basemem(); // error...

The problem, dear OP, is that d2 may use all functions from its base
B, but functions *outside* d2 may not use those inherited from Base.

See it this way:
The public part of a class is the outside image you let the rest see.
The protected part is the purse, you only let your family
(descendants) see.
The private part lies within your underpants.

If one of your descendants is proud of you, he inherits publicly form
you and puts your photo on a badge on the lapel, for everyone to see.

But if you embarrass him, and wants to hide the fact that he inherits
from you, he will do it privately. He is putiing you within his
underpants, no way for the others to see you.

Maybe that helps you understand the idea of the kinds of inheritance.

Regards,

Zara
Oct 11 '06 #3
Zara wrote:
>
On 10 Oct 2006 07:56:52 -0700, "asdf" <li*********@gmail.comwrote:

[...] *snipped* : Some nice analogies ;)
Dear Zara,

I assume that with this nick, you are a girl !

Therefore, I would like to ask you a question; Following your analogy,
it seems to me that there is a field of confusion. What happens if we
marry ?

Will I have access to your private members ? :)
Will you have access to mine ?
Will I be the only one to be able to access to them ?

What will be the state of... our common bank account ?

Cheers, Keep it up ;)
K

Oct 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles L | last post by:
Does anyone know where I can find errata for Stan Lippman's 'C++ Primer 2nd Edition'? Charles Leng
1
by: Ciko | last post by:
I had a look at this book: "C Primer Plus, Fifth Edition Stephen Prata " and I found simply fantastic. My english is little but I had no problem to understand it. Was wondering if you...
3
by: huangshan | last post by:
hi all I read "C++ Primer, Fourth Edition" , but can't understand this sentence "By making the parameters const references, we allow types that do not allow copying." in "16.1. Template...
17
by: arnuld | last post by:
Exercise 4.28: Write a program to read the standard input and build a vector of ints from values that are read. Allocate an array of the same size as the vector and copy the elements from the...
2
by: W. Watson | last post by:
Is there a primer out there on these two items? I have the Python tutorial, but would like either a Tkinter tutorial/primer to supplement it, or a primer/tutorial that addresses both. Maybe there's...
2
by: xianwei | last post by:
First, typedef struct pair { Node *parent; Node *child; } Pair; static Pair SeekItem(cosnt Item *pI, const Tree *pTree) { Pair look;
1
by: Kveldulv | last post by:
Hi all, here is the code: http://pastebin.com/m6e74d36b I'm stuck at highfink constructor, last line before #endif. As parameters, I have reference to one parent class and int member of another...
1
by: mmdspam | last post by:
Hi, Can someone please tell me the answer to exercise 1.20 in C++ Primer 4th edition. I am stuck on this question. Thank you in advance
2
by: jerry | last post by:
can anyone tell me where can i get the keys to c++ primer 4th edition, pdf or chm type are both ok. thank you!
2
by: shezad.ps3 | last post by:
Hi, I need to make my c++ knowldge deeper as it is, I've got the third edition of the Lipman book but I have been told that the latest revision is a tremendous improvement from the one I've...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.