   Derived Class Functions
  If I have 2 classes:class MyBaseClass  {public:  int MyFunction(int myInt);protected:  int myInteger;};int MyBaseClass::MyFunction(int myInt)  {  myInteger=myInt+22;  return myInteger;}class MyDerivedClass:public MyBaseClass  {public:  int MyFunction(int myInt);};int MyDerivedClass::MyFunction(int myInt)  {  myInteger=myInt-43;  return myInteger;}I know that calling MyFunction(43) from a MyDerivedClass instance will return 0, but what if I do this:void* myPointer=(void*)new MyDerivedClass;((MyBaseClass*)myPointer)->MyFunction(0);that is, calling MyFunction from a MyDerivedClass but using the (MyBaseClass*) thing. Will it call MyDerivedClass::MyFunction and return -43 or MyBaseClass::MyFunction and return 22? I looked at some tutorials but they disagreed with each other.   
  The function is not virtual, so the dynamic type of the object is not considered.The static type of the pointer expression is MyBaseClass*.Thus MyBaseClass::MyFunction will be called.virtual -> the dynamic type of the object (as given to new) determines the function that gets called.non-virtual -> the static type of the variable (be it object, pointer or reference) determines function that gets called.Note that going through a void* like that is a rather bad idea: it could break spectacularly in presence of multiple or virtual inheritance. Pointers to derived classes are implicitely convertible to pointers to base classes -- rely on that.   ;  Then would it work if I put virtual in front of the function declaration? Or do I have to make it a pure virtual? Or will it just not work when using the void*?   ;  It should work with the virtual declaration, but please, please don't use void*.   ;  Even so, it's not guaranteed to work if the function is virtual. When you cast something to void * the only thing you can reliably do with it is to cast the pointer back to the same type that it originally was, in this case, a MyDerivedClass pointer. Casting through a void * will break if the base address of the base and derived class are different, which could happen if you make the function virtual in the derived class but not the base class or if you have multiple inheritance. In general, avoid using void pointers.   