Jan 22, 2009

Pure virtual function can has body

Pure virtual function can has body
A pure virtual function is a virtual function that you want to force derived classes to override. If a class has any unoverridden pure virtuals, it is an "abstract class" and you can't create objects of that type
Pure virtual destructor should have body: if there is no body, the child class cannot be instantiated, because when destroy the child’s object, which call base class destructor. The reason declaring pure keyword is that we want to prevent base class being instantiated (no other pure virtual function in base class).
http://www.gotw.ca/gotw/031.htm

No comments:

Post a Comment