Re: basic question on C++
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 02/05/04
- Next message: Chris \( Val \): "Re: Vector of Structs and I/O"
- Previous message: Chris \( Val \): "Re: c++ cin question"
- In reply to: Leor Zolman: "Re: basic question on C++"
- Next in thread: jeffc: "Re: basic question on C++"
- Reply: jeffc: "Re: basic question on C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 5 Feb 2004 23:00:47 +1100
"Leor Zolman" <leor@bdsoft.com> wrote in message
news:i8a3205v3nh9p69nnh8qn666hl81hr4hqt@4ax.com...
| On Wed, 04 Feb 2004 17:21:50 -0800, Digital Puer
| <digital_puer@hotjail.comet> wrote:
|
| >On a job interview question, this was asked:
| >
| > From the point of view of a derived class, how do you set
| >variables in the base class to be all private? Give
| >an example using class A (base) and B (derived).
| >
| >Any ideas? I can't clarify because that's all that was given.
| >
|
| All I can think of is that "how do you set variables in the base class
| to be all private" is meant as if it were followed with "...to the
| derived class" (since the sentence begins, "From the point of view of
| a derived class"). So another way of asking this would be, "How can a
| derived class make sure that all the accessible variables it inherits
| from its base class are not accessible to its further derived
| classes". That would be via private inheritance:
| class B : private A {
| ...
| };
Although I don't see any clarification of the question from
the OP as yet, I get the feeling(seeing the word set), that
the OP might be asking how to set(read initialise), the private
data members from the derived class(not necessarilly due to
private inhetirence).
If that is the case, then here is a third guess ;-).
class Base
{
private:
int N;
public:
Base( const int& n ) : N( n ) {}
};
class Derived : private Base
{
public:
Derived() : Base( 100 ) {}
};
Cheers.
Chris Val
- Next message: Chris \( Val \): "Re: Vector of Structs and I/O"
- Previous message: Chris \( Val \): "Re: c++ cin question"
- In reply to: Leor Zolman: "Re: basic question on C++"
- Next in thread: jeffc: "Re: basic question on C++"
- Reply: jeffc: "Re: basic question on C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|