Created
March 21, 2019 14:40
-
-
Save RDCH106/a965bd2f403ebd6c5b99e731b97c42ba to your computer and use it in GitHub Desktop.
C++ Inheritance with functions with default parameter example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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