|
-
March 29th, 2004, 10:07 AM
#1
static array of base class pointers to point to derived classes dynamically ?
Hey guys,
here is the problem:
I have to keep an static array of pointers of type base class , and I should be able to assign each of these pointers to any of the derived class..
here is the code...
class Base
{
public:
static Base* basePtr[10];
}
class derived1 : public Base
{ }
class derived2 : public Base
{}
now in my main.cpp I want to be able to create objects of derived1 or derived2 and assign the basePtr to point to them....
how do I do that???
.....
...
derived1 d1
Base::basePtr[1] = &d1 // I tried this approach, the problem is...does this mean I have to have 10 different classes of d1 or d2 and then assign each of their references to the basePtr ??? Is there way to do this dynamically so that I do some thing like the following
Base::basePtr[1] = new derived1;
Pls help..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|