From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/cpp/smtptr/shared_pointer_is_a.cc | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 graphs/cpp/smtptr/shared_pointer_is_a.cc (limited to 'graphs/cpp/smtptr/shared_pointer_is_a.cc') diff --git a/graphs/cpp/smtptr/shared_pointer_is_a.cc b/graphs/cpp/smtptr/shared_pointer_is_a.cc new file mode 100644 index 0000000..b6dcb95 --- /dev/null +++ b/graphs/cpp/smtptr/shared_pointer_is_a.cc @@ -0,0 +1,47 @@ +#include "shared_pointer.hh" + +class Animal +{ +public: + virtual ~Animal() + {} +}; + +class Cat : public Animal +{ +public: + void meow() + { + std::cout << "Meow!\n"; + } +}; + +class Dog : public Animal +{ +public: + void bark() + { + std::cout << "Woof!\n"; + } +}; + +int main() +{ + SharedPointer animalPtr{ new Cat }; + if (animalPtr.is_a()) + { // true + std::cout << "The pointer points to a Cat.\n"; + } + + SharedPointer animalPtr2{ new Dog }; + if (animalPtr2.is_a()) + { // false + std::cout << "The pointer points to a Cat.\n"; + } + else if (animalPtr2.is_a()) + { + std::cout << "The pointer points to a Dog.\n"; + } + + return 0; +} -- cgit v1.2.3