   Calling a derived member function to an inherited class, from a pointer. (c++)
  ~Calling a derived member function to an inherited class, from a pointer. (c++)~I have an array of pointers to the base class where there are a few classes inherited off of.I cant just do aBaseclass * array[3] = {NULL};array[0] = new derivedclass; array[0]->derivedclassfunction();VB 6 will only allow me to call functions of the base class even though I allocated the derived class for the pointer to point to.  I thought you could just call a derived function when you allocate it to be a derived class.  What do I need to do to be able to call the derived member functions?[edited by - skow on July 30, 2003 10:31:04 PM]
  You need a pointer to that derived class to call derivedmethods.Call the method and then put it in there, or use virtual functions. ;  Ohh so you cant add acessors to a derived class with new member variables?  When using an pointer of the base class?   [edited by - skow on July 30, 2003 10:55:17 PM];  If you cast the pointer, VC++ should shut up.(derivedClass *)baseClassPtr->DerivedClassFunc();Just make absolutely sure that DerivedClassFunc() will never get called from something other than a derivedClass.  Otherwise your program will barf. ;  Pointers to base classes (this includes arrays) can only access members of the base class. This is what virtual functions are for...to allow you to use a base pointer and get derived class functionality. ;  BitBlt: I tried that, I'm still getting an error saying the derived functions not part of the base class SpaceRogue: Yeah but i dont want to make virtual functions for acessors for variables the base class doesnt have.  Virtual functions are good for overiding functiosn the base class already has, but i cant make a virtual acressor for a vairable it doesnt have (i dont want to make it an abstract class)    [edited by - skow on July 30, 2003 11:03:34 PM];  I assume since it''s not working that you don''t have the function declared as a virtual function.  Can you post part of the class code? ;  (Since you edited your last message while I was writing...)If you add new functions/variables to your interface, then you can''t use the base pointer to access them. ;  Damn that messes up my plan There is no way around that i assume? ;  Well I guess the main thing is why are you using an array of base pointers when you''re wanting to access methods specific to the derived class?  Would all classes derived from base have that same method?  If not, then how could you possibly expect to call the function using a base pointer.  If so, why wouldn''t you make it virtual?  What is it exactly that you are trying to do?  Maybe there''s a better way. 