From 89609d0937df160477b934b6f352fb16db8ddeb4 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Fri, 11 Apr 2025 12:41:23 -0400 Subject: [PATCH] adding name hiding example --- lectures/25_inheritance/name_hiding.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lectures/25_inheritance/name_hiding.cpp diff --git a/lectures/25_inheritance/name_hiding.cpp b/lectures/25_inheritance/name_hiding.cpp new file mode 100644 index 0000000..698f7f2 --- /dev/null +++ b/lectures/25_inheritance/name_hiding.cpp @@ -0,0 +1,22 @@ +#include + +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; +}