virtual function questions

why if a class has a pure virtual function, it cannot instantiate an object of its own? i read on this site tutorial, it says:

because in abstract base classes at least one of its members lacks implementation we cannot create instances (objects) of it


don't really understand...
Because its functions wouldn't exist. You can't create an instance of a class where some of the function code hasn't been written. What should happen if you tried to call that function? It's meaningless.
i thought so... but, it has crossed my mind too that why it doesn't designed, like, if it calls the virtual function, it would results an error and thus the calling for that method is illegal (means that you have to erase that snippet outta your source code)
Sometimes you want to prohibit instances of a class. It is common to have an abstract base class that other classes inherit from. The abstract class then just specify the interface and the derived classes have to implement the function that was pure virtual in the base class.
Last edited on
pure virtual does not mean you may not write definition for that virtual function as wel :D

abstract classes(those which have at least 1 virtual method) are used as interfaces or "generic-behaviour" for derived classes.
Topic archived. No new replies allowed.