Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RDCH106/a965bd2f403ebd6c5b99e731b97c42ba to your computer and use it in GitHub Desktop.
Save RDCH106/a965bd2f403ebd6c5b99e731b97c42ba to your computer and use it in GitHub Desktop.
C++ Inheritance with functions with default parameter example
#include <iostream>
#include <string>
#include <vector>
struct A
{
void f_sinarg() {
f(3);
}
protected:
virtual void f(int a) {
std::cout << "A: " << a << std::endl;
}
};
struct B : public A
{
protected:
void f(int a) override {
std::cout << "B: " <<a << std::endl;
}
};
int main()
{
A a;
a.f_sinarg();
B b;
b.f_sinarg();
A *ab = &b;
ab->f_sinarg();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment