473,411 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

answer?

class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know
This is exercise was in a test of C++ and i'm not rreally sure what to
choose. Could you give me an answer and tell me the relationship betwen
dhe public, private and protected of the variables in the derived
class? I supose that you have understand that I'm a begginer.

Sep 5 '05 #1
7 1281

"il_santo" <al*******@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know
This is exercise was in a test of C++ and i'm not rreally sure what to
choose. Could you give me an answer and tell me the relationship betwen
dhe public, private and protected of the variables in the derived
class? I supose that you have understand that I'm a begginer.


For you, the correct answer is clearly "g)"...
Sep 5 '05 #2
Hi,

first off be careful sending mails like that to the group. There are
individuals that respond in a not-so-polite manner sometimes. I'd
always try to at least have a stab at an answer before posting, perhaps
including your reasoning. That way you'll get the most from the
newsgroup and will find results the quickests.
So if I were you, I'd take a first look at what it the access modifiers
public, private and protected mean. What do you think they mean? i.e.
what's the difference between public and private? public and protected?
Or maybe put another way, if you didn't want a variable to be
accessible in a derived/subclass, how would you declare it?

Also. if you wanted a variable to be available only within the class in
which it is defined and derived/subclasses, how would you declare it?

therein lies the answer to your question... :)

Cheers

GrahamO

Sep 5 '05 #3
il_santo wrote:
class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know
This is exercise was in a test of C++ and i'm not rreally sure what to
choose. Could you give me an answer and tell me the relationship betwen
dhe public, private and protected of the variables in the derived
class? I supose that you have understand that I'm a begginer.


Hi

maybe you should have a look at:

http://www.parashift.com/c++-faq-lit...heritance.html

All other topics covered by the faq are
interesting too, especially if you are a beginner
like you told.

Manfred
Sep 5 '05 #4
il_santo wrote:
class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know
This is exercise was in a test of C++ and i'm not rreally sure what to
choose. Could you give me an answer and tell me the relationship betwen
dhe public, private and protected of the variables in the derived
class? I supose that you have understand that I'm a begginer.


There is no correct answer to the question (except maybe g). I would
guess that the person who asked this question doesn't understand
protected access. Because access to var 'a' does not depend only on
which class is making the access, it also depends on how the access is
made. So as the question is posed it cannot be answered.

john
Sep 5 '05 #5
John Harrison wrote:
il_santo wrote:
class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know

There is no correct answer to the question (except maybe g). I
would guess that the person who asked this question doesn't
understand protected access.


I would say the answer is 'only c'. The example uses private
derivation, so the private and protected members of the base
class are not accessible by the derived class.
Because access to var 'a' does not depend only on
which class is making the access, it also depends on how the
access is made.


Supposing the derivation were public, when does it depend
on how the access is made? Member functions of an instance
of class Y (which is what I presume the OP is referring to)
can access the protected variables of class X.

Sep 6 '05 #6
* Old Wolf:
John Harrison wrote:
il_santo wrote:
class X { class Y : class X {
protected: public:
int a; void g();
public: int k;
int c; };
private:
int b;
public:
void f();
};

An object of Y could access the var:
a) a,b,c
b)a,b
c)only c
d)only a
e)a,c
f)c,b
g)I don't know


There is no correct answer to the question (except maybe g). I
would guess that the person who asked this question doesn't
understand protected access.


I would say the answer is 'only c'. The example uses private
derivation, so the private and protected members of the base
class are not accessible by the derived class.


A C cast casts away that inaccessability, in a standard-conforming way, and
the operative word is "could"... ;-)

Furthermore, since nothing about portability and standard conformance is
mentioned, I wouldn't have any problems accessing the 'b' variable.

What do you bet a _correct_ answer (except g) wouldn't give full marks?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 6 '05 #7
* Alf P. Steinbach:
[rubbish]


I've got the flu; disregard please.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 6 '05 #8

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

Similar topics

3
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
4
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
33
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good...
2
by: amelia170 | last post by:
I am creating a database with a yes or no answer for question 1. Based on that answer, (if they answer yes) they will answer question 2, then three....However, if they answer no to question one, I...
14
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
12
by: Bernie Yaeger | last post by:
I asked two fairly simple questions, or so I thought, but have received no ideas at all. 1. What is the control that MS uses in Outlook Express that contains attachments? It appears to be a...
2
by: windsorben | last post by:
I'd like to have an image appear after the student answers each short answer question correctly. I can't seem to get it to work properly. See code below. Thanks! <html> <head>...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...
0
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...

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.