By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

help for inheritance problem

P: n/a
Hi all,

I am new in c++. I met such a problem:

class base{

protected:
int a[10];
int b;
public:
.....
}

if I have two child classes,
class child1:public base
{
}
class child2:public base
{
}

I want to do:
(1) change the values of a[] in child1, for example set a[0]=1;
(2) change the values of a[] in child 2, for example set a[1]=2 and I
can get the value a[0]

how I can do? Thanks a lot

Nov 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
David wrote:
I am new in c++. I met such a problem:

class base{

protected:
int a[10];
int b;
public:
.....
}

if I have two child classes,
class child1:public base
{
}
class child2:public base
{
}

I want to do:
(1) change the values of a[] in child1, for example set a[0]=1;
(2) change the values of a[] in child 2, for example set a[1]=2 and I
can get the value a[0]

how I can do? Thanks a lot
Just use the syntax you typed in right here. a[0]=1; a[1]=2; and
so on. Also read the FAQ 5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 8 '06 #2

P: n/a
David wrote:
I am new in c++. I met such a problem:

class base{

protected:
int a[10];
int b;
public:
.....
}

if I have two child classes,
class child1:public base
{
}
class child2:public base
{
}

I want to do:
(1) change the values of a[] in child1, for example set a[0]=1;
(2) change the values of a[] in child 2, for example set a[1]=2 and I
can get the value a[0]

how I can do? Thanks a lot
why not-

class child1:public base
{
public:
void update()
{ a[0] = 1; }
}


--
Nick Keighley

Nov 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.