We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This wasn't not interesting. But I made a little bit interesting, by changing the way of doing it.
#include<iostream>#include<memory> // std::unique_ptr, std::make_unique#include<array> // std::arraystructShape{// optional noexcept specifiervirtualvoidtriangle()constnoexcept=0;virtual~Shape()=default;};structTriangle:publicShape{voidtriangle()constnoexceptoverride{std::cout<<"I am a triangle\n";}};structIsosceles:publicTriangle{voidtriangle()constnoexceptoverride{std::cout<<"I am an isosceles triangle\n";}};structEquilateralfinal:publicIsosceles{voidtriangle()constnoexceptoverride{std::cout<<"I am an equilateral triangle\n";}};intmain(){conststd::array<std::unique_ptr<Shape>,3>obj{std::make_unique<Equilateral>(),// element 1std::make_unique<Isosceles>(),// element 2std::make_unique<Triangle>()// element 3};for(auto&it:obj)it->triangle();return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Multi Level Inheritance
You are viewing a single comment's thread. Return to all comments →
This wasn't not interesting. But I made a little bit interesting, by changing the way of doing it.