CS Electrical And Electronics
@cselectricalandelectronics

Virtual functions in Cpp?

All QuestionsCategory: Cpp LanguageVirtual functions in Cpp?
CS Electrical And Electronics Staff asked 4 years ago

I need short information.

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

Virtual Functions In Cpp
 

  1. The virtual functions must be members of some classes.
  2. They cannot be static members.
  3. They are accessed by using object pointers.
  4. A virtual function can be a friend of another class.
  5. A virtual function in a base class must be defined, even though it may not be used.
  6. The prototypes of the base class version of a virtual functions and all the derived class versions must be identical if two functions with the same name have different prototypes C++ considers them as overloaded functions, and the virtual function mechanism is ignored.
  7. We cannot have virtual constructors, but we can have virtual destructors.
  8. While a base pointer can point to any type of the derived object the reverse is not true that is to say we cannot use a pointer to a derived class to access an object of the base type.
  9. When a base pointer points to a derived class incrementing or decrementing it will not make it to point to the next object of the derived class .it is incremented or decremented only relative to its base type, therefore, we should not use this method to move the pointer to the next object.
  10. If a virtual function is defined in the base class, it need not be necessarily redefined in the derived class.in such cases, a call will invoke the base function.