hi all, i am not-so-new to C++, but then ,yea, a newbie XD
ok, here is the question.
first i have a base class call Item, and it have 3 sub class.
Now i need to make an array total of 100 item, that can store any of that 3 sub class of Item class, so the , question is, how do i need to declare the array? i cannot make it like:

Book book[25];
Stationery stationery[25];
Multimedia multimedia[50];

becuase they can't share the number...

Recommended Answers

All 2 Replies

const unsigned int MAX = 25;
BaseClass * pBC[MAX];

Make sure BaseClass has some virtual function if needed.

Now you can static bind or dynamic bind.

Static Bind :
pBC[0] = new BaseClass
pBC[1] = new InherietFromBaseClass
//and so on

Dynamic binding
cout<<"1 for baseclass, 2 for InherietFromBaseClass, //and so on";
int opt = 0;
cin >> opt;
if(opt == 1) pBC[0] = new BaseClass
//and so on

hym...ok, i think this help, thankyou ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.