answersLogoWhite

0


Best Answer

Overloading simply means re-using the same function name with different argument types or a different number of arguments. The implementations may or may not be same. However, if the implementations are exactly the same, only differing by the types they operate open, the function can be implemented as a function template rather than individual overloads. In this way, the compiler can generate the overloads on an as-required basis.

Overriding only occurs in class hierarchies where a base class declares one or more virtual functions. Derived classes can override the implementation of these virtual methods to provide more specific implementations. When invoking a virtual method, the most-derived override of that method is always invoked, thus ensuring an object behaves according to its actual type, even when that type is not known to the calling code. This allows code to be written in a more generic manner using a virtual interface.

Virtual methods can also be declared pure virtual. This means that the base class that declares the method becomes an abstract base class and cannot be instantiated in its own right (typically used for conceptual classes that define interfaces). Derivatives must provide an implementation for the pure virtual methods they inherit otherwise they too become abstract. Once overridden, a pure virtual method reverts to virtual for all subsequent derivatives in the hierarchy. The base class may provide an implementation, but is not required to do so.

The main difference between a virtual and pure-virtual interface is that pure-virtual interfaces must be overridden in order to create a concrete class, whereas virtual interfaces need not be overridden.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Contrast the difference between method overloading and overridding?
Write your answer...
Submit
Still have questions?
magnify glass
imp