diff --git a/src/data/roadmaps/cpp/content/107-structures-and-classes/102-multiple-inheritance/100-diamond-inheritance.md b/src/data/roadmaps/cpp/content/107-structures-and-classes/102-multiple-inheritance/100-diamond-inheritance.md index cd88336dc..136b45012 100644 --- a/src/data/roadmaps/cpp/content/107-structures-and-classes/102-multiple-inheritance/100-diamond-inheritance.md +++ b/src/data/roadmaps/cpp/content/107-structures-and-classes/102-multiple-inheritance/100-diamond-inheritance.md @@ -7,39 +7,37 @@ To resolve this ambiguity, you can use virtual inheritance. A virtual base class *Example:* ```cpp -#include -using namespace std; +#include class Base { public: void print() { - cout << "Base class" << endl; + std::cout << "Base class" << std::endl; } }; class Derived1 : virtual public Base { public: void derived1Print() { - cout << "Derived1 class" << endl; + std::cout << "Derived1 class" << std::endl; } }; class Derived2 : virtual public Base { public: void derived2Print() { - cout << "Derived2 class" << endl; + std::cout << "Derived2 class" << std::endl; } }; class Derived3 : public Derived1, public Derived2 { public: void derived3Print() { - cout << "Derived3 class" << endl; + std::cout << "Derived3 class" << std::endl; } }; -int main() -{ +int main() { Derived3 d3; d3.print(); // Now, there is no ambiguity in calling the base class function d3.derived1Print(); @@ -50,4 +48,4 @@ int main() } ``` -In the code above, `Derived1` and `Derived2` are derived from the `Base` class using virtual inheritance. So, when we create an object of `Derived3` and call the `print()` function from the `Base` class, there is no ambiguity, and the code executes without any issues. \ No newline at end of file +In the code above, `Derived1` and `Derived2` are derived from the `Base` class using virtual inheritance. So, when we create an object of `Derived3` and call the `print()` function from the `Base` class, there is no ambiguity, and the code executes without any issues.