Abstract Base Class

hi,

base class becomes abstract class, when it containes atleast one pure virtual function.

so technically there is no need to make every virtual func. pure, as it has the same affect (you cant use base class'instances), as if you would make pure only one of them

is this a good idea or not and why?

ty
Last edited on
You have to analyze every function independently to determine whether they should be pure or not. yes you only need one pure virtual function to make an ABC(Abstract Base Class). That doesn't mean that you shouldn't make others pure within the same class. You should make every virtual function pure that needs to be pure. You don't want to have empty or non-useful function definitions in a base class if there is no point to them. In some cases it is correct to make all of the functions of an ABC pure virtual.
first of all sorry that i used interface instead of ABC

- so there is no way to make just some of the virtual func. pure, and still be able to use other non-pure func. of ABC?

- "You don't want to have empty or non-useful function definitions in a base class if there is no point to them."
-> but what if there is for some of them? Than your are no longer able to implement and use other non-pure func. (in bass class)!

- if your making an abstract class, why not making it an interface, as if some func. are note pure virtual it doesnt matter, because it will have the same affect, that is, a restriction of using base class' object and the need of overriding and implementing the pure func.. If you dont make it an interface, you'll just have more work with non-sense implementations of bases (non-pure virtual) functions?


ty for now and in advance!
Last edited on
You make functions virtual if you want derived classes to be able to override them.
You make virtual functions pure in a base class if the base class cannot provide a useful
implementation of the function (ie, every concrete derived class overrides it anyway).

You can mix and match any number of virtual and pure virtual functions in a class as you'd like.
Topic archived. No new replies allowed.