What is the difference between overloading and overriding in C++?

PointOverloadingOverriding
WhereSame scopeBase and derived class
ParametersDifferentSame
Needs virtualNoYes (for run time behavior)
DecidedCompile timeRun time
#include <iostream>

struct Base {
    virtual void f() const { std::cout << "Base::f\n"; }
    void g(int) const { std::cout << "g(int)\n"; }
    void g(double) const { std::cout << "g(double)\n"; }       // overloading
};

struct Derived : Base {
    void f() const override { std::cout << "Derived::f\n"; }    // overriding
};

int main() {
    Derived d;
    const Base& b = d;
    b.f();
    b.g(1);
    b.g(1.5);
}
Output

Derived::f
g(int)
g(double)

See Polymorphism and Function Overloading.


Learn more about the similar topics:
Tutorials
C++ Classes and Objects
C++ Constructors and Destructors
C++ Access Specifiers and Encapsulation
C++ Inheritance
C++ Polymorphism and Virtual Functions
C++ Abstract Classes and Interfaces
C++ Operator Overloading
Exercises & Assignments
Build a BankAccount class
Calculate areas with polymorphism
Overload operators for a Money class
Interview Questions & Answers
What is the difference between struct and class in C++?
What is a constructor in C++ and what are its types?
What is a destructor in C++?
What is the difference between overloading and overriding in C++?
What is a virtual function in C++?
What is a pure virtual function and an abstract class in C++?
What is the static keyword in C++?