Just started to see the virtual keyword, for this thing to understand is not too clear, the virtual keyword that I understand is a pointer to a subclass of the base class dad * a=new son (), if the dad class method using the virtual keyword in the definition, the son also defines this method, so the method that subclass overrides the superclass method, if there is no virtual, call the superclass method, do not know right, hope bosses, correct
CodePudding user response:
Virtual is tells the compiler, the position taken in a virtual table placeholder, save a space, the corresponding virtual table function Pointers to 0, for behind the reserved method interface inheritance, polymorphism
CodePudding user response:
Received, ali ga is much,,,
CodePudding user response:
Virtual function is one of the cornerstone of polymorphism, is defined as the parent class, the actual use of time can be introduced into subclasses, and a subclass of virtual rewritten, so in the end use is a subclass of function, so it is more flexible,