adding name hiding example
This commit is contained in:
committed by
JamesFlare1212
parent
107a578154
commit
89609d0937
22
lectures/25_inheritance/name_hiding.cpp
Normal file
22
lectures/25_inheritance/name_hiding.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
class A {
|
||||
public:
|
||||
void func(int x) {
|
||||
std::cout << "A::func(int): " << x << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
class B : public A {
|
||||
public:
|
||||
void func(double y) {
|
||||
std::cout << "B::func(double): " << y << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
B b;
|
||||
b.func(10); // Calls B::func(double)
|
||||
b.func(10.5); // Calls B::func(double)
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user