virtual fuction

Hi there, I am declare a pure virtual function in a based class, this base class has two derived classes, but I realized I only want to implemented the pure virtual in one of the two. Is this possible? how could I do this?

Thanks
Sure. Just implement it in the one class only. Of course, the other derived class will also be abstract as it has an outstanding pure virtual.

But think about it. This must be the case. Suppose the derived class with no implementation for the function were not abstract, i.e. you could instantiate it. Then you could call the pure virtual function via a pointer to the base which was in fact pointing to an instance of the class with no implementation of the function. That's a runtime error because there is no pointer to the required function in the vtable.
Topic archived. No new replies allowed.