{"id":34502,"date":"2021-05-23T09:13:09","date_gmt":"2021-05-23T03:43:09","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/"},"modified":"2025-06-20T18:59:22","modified_gmt":"2025-06-20T13:29:22","slug":"c-inheritance","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/","title":{"rendered":"Inheritance in C++"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-inheritance-in-c\">What is Inheritance in C++?<\/h2>\n\n\n\n<p>Inheritance in C++ is a process where one class acquires the properties and behaviors of another class. The class that inherits is the <b>derived class<\/b> (or subclass). The class it inherits from is the <b>base class<\/b> (or superclass).<\/p>\n\n\n\n<p>Inheritance offers several key benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Code Reusability:<\/b> You write common code once in the base class. Then, derived classes reuse it without rewriting. This saves time and reduces errors.<\/li>\n\n\n\n<li><b>Reduced Development Time:<\/b> Reusing existing code speeds up development. You focus on new features instead of duplicating efforts.<\/li>\n\n\n\n<li><b>Easier Maintenance:<\/b> Changes in the base class apply to all derived classes. This simplifies updates and bug fixes across your program.<\/li>\n\n\n\n<li><b>Improved Readability:<\/b> Code becomes more organized and easier to understand. You see clear relationships between classes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-implement-inheritance-in-c\">How to Implement Inheritance in C++<\/h2>\n\n\n\n<p>Implementing inheritance involves declaring a derived class from a base class. Here is the basic syntax:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass DerivedClass : access_specifier BaseClass {\n    \/\/ Members of DerivedClass\n};\n<\/pre><\/div>\n\n\n<p>Here, <code>access_specifier<\/code> defines how members of the base class are inherited in the derived class. Common specifiers include <b>public<\/b>, <b>protected<\/b>, and <b>private<\/b>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"access-specifiers-in-inheritance\">Access Specifiers in Inheritance<\/h2>\n\n\n\n<p>Access specifiers control member visibility in derived classes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Public Inheritance:<\/b> Base class public members become public in the derived class. protected members become protected. private members remain private and are not directly accessible.<\/li>\n\n\n\n<li><b>Protected Inheritance:<\/b> Base class public and protected members become protected in the derived class. private members remain private.<\/li>\n\n\n\n<li><b>Private Inheritance:<\/b> Base class public and protected members become private in the derived class. private members remain private.<\/li>\n<\/ul>\n\n\n\n<p>Here is a table summarizing access in derived classes:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Base Class Access<\/th><th>Public Inheritance<\/th><th>Protected Inheritance<\/th><th>Private Inheritance<\/th><\/tr><\/thead><tbody><tr><td>public<\/td><td>public<\/td><td>protected<\/td><td>private<\/td><\/tr><tr><td>protected<\/td><td>protected<\/td><td>protected<\/td><td>private<\/td><\/tr><tr><td>private<\/td><td>Not accessible<\/td><td>Not accessible<\/td><td>Not accessible<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-inheritance-in-c\">Types of Inheritance in C++<\/h2>\n\n\n\n<p>C++ supports five main types of inheritance. Each type serves different purposes for class relationships and code organization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-single-inheritance\">1. Single Inheritance<\/h3>\n\n\n\n<p>Single inheritance involves one derived class inheriting from one base class. This is the simplest and most common type of inheritance.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/single-inheritance.webp\"><img decoding=\"async\" width=\"592\" height=\"695\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/single-inheritance.webp\" alt=\"Single Inheritance in C++\" class=\"wp-image-108757\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/single-inheritance.webp 592w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/single-inheritance-256x300.webp 256w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/single-inheritance-150x176.webp 150w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"example\">Example:<\/h4>\n\n\n\n<p>You have a <code>Vehicle<\/code> base class. Then, you create a <code>Car<\/code> class that inherits from <code>Vehicle<\/code>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\n\/\/ Base class\nclass Vehicle {\npublic:\n    void accelerate() {\n        std::cout &amp;lt;&amp;lt; &quot;Vehicle is accelerating.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Derived class\nclass Car : public Vehicle {\npublic:\n    void drive() {\n        std::cout &amp;lt;&amp;lt; &quot;Car is driving.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Car myCar;\n    myCar.accelerate(); \/\/ Inherited from Vehicle\n    myCar.drive();      \/\/ Member of Car\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Vehicle is accelerating.\nCar is driving.<\/pre>\n\n\n\n<p>In this example, <code>Car<\/code> inherits <code>accelerate()<\/code> from <code>Vehicle<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-multiple-inheritance\">2. Multiple Inheritance<\/h3>\n\n\n\n<p>Multiple inheritance lets a derived class inherit from multiple base classes. This combines features from several independent classes into one.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multiple-inheritance-cpp.jpg\"><img decoding=\"async\" width=\"602\" height=\"701\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multiple-inheritance-cpp.jpg\" alt=\"Multiple Inheritance in C++\" class=\"wp-image-108758\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multiple-inheritance-cpp.jpg 602w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multiple-inheritance-cpp-258x300.jpg 258w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multiple-inheritance-cpp-150x175.jpg 150w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"example\">Example:<\/h4>\n\n\n\n<p>You have a <code>Writer<\/code> class and an <code>Artist<\/code> class. You create a <code>WriterArtist<\/code> class that inherits from both.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\n\/\/ Base class 1\nclass Writer {\npublic:\n    void write() {\n        std::cout &amp;lt;&amp;lt; &quot;Writer is writing a story.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Base class 2\nclass Artist {\npublic:\n    void draw() {\n        std::cout &amp;lt;&amp;lt; &quot;Artist is drawing a picture.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Derived class inheriting from Writer and Artist\nclass WriterArtist : public Writer, public Artist {\npublic:\n    void create() {\n        std::cout &amp;lt;&amp;lt; &quot;WriterArtist is creating something new.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    WriterArtist person;\n    person.write(); \/\/ Inherited from Writer\n    person.draw();  \/\/ Inherited from Artist\n    person.create();\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Writer is writing a story.\nArtist is drawing a picture.\nWriterArtist is creating something new.<\/pre>\n\n\n\n<p><code>WriterArtist<\/code> has access to <code>write()<\/code> from <code>Writer<\/code> and <code>draw()<\/code> from <code>Artist<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-multilevel-inheritance\">3. Multilevel Inheritance<\/h3>\n\n\n\n<p>Multilevel inheritance involves a chain of inheritance. A class inherits from a base class, and then another class inherits from this derived class.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp.webp\"><img decoding=\"async\" width=\"814\" height=\"916\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp.webp\" alt=\"Multilevel Inheritance in C++\" class=\"wp-image-108761\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp.webp 814w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp-267x300.webp 267w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp-768x864.webp 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/multilevel-inheritance-cpp-150x169.webp 150w\" sizes=\"(max-width: 814px) 100vw, 814px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"example\">Example:<\/h4>\n\n\n\n<p>You have a <code>Animal<\/code> class. Then, <code>Mammal<\/code> inherits from <code>Animal<\/code>. Finally, <code>Dog<\/code> inherits from <code>Mammal<\/code>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\n\/\/ Grandparent class\nclass Animal {\npublic:\n    void eat() {\n        std::cout &amp;lt;&amp;lt; &quot;Animal eats food.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Parent class\nclass Mammal : public Animal {\npublic:\n    void breathe() {\n        std::cout &amp;lt;&amp;lt; &quot;Mammal breathes air.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Child class\nclass Dog : public Mammal {\npublic:\n    void bark() {\n        std::cout &amp;lt;&amp;lt; &quot;Dog barks loudly.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Dog myDog;\n    myDog.eat();    \/\/ Inherited from Animal\n    myDog.breathe(); \/\/ Inherited from Mammal\n    myDog.bark();\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Animal eats food.\nMammal breathes air.\nDog barks loudly.<\/pre>\n\n\n\n<p>Here, <code>Dog<\/code> gets features from both <code>Mammal<\/code> and <code>Animal<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-hierarchical-inheritance\">4. Hierarchical Inheritance<\/h3>\n\n\n\n<p>Hierarchical inheritance occurs when multiple derived classes inherit from a single base class. This is useful for creating a family of related classes that share common characteristics.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hiarchical-inheritance-cpp.webp\"><img decoding=\"async\" width=\"602\" height=\"701\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hiarchical-inheritance-cpp.webp\" alt=\"Hierarchical Inheritance in C++\" class=\"wp-image-108759\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hiarchical-inheritance-cpp.webp 602w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hiarchical-inheritance-cpp-258x300.webp 258w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hiarchical-inheritance-cpp-150x175.webp 150w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"example\">Example:<\/h4>\n\n\n\n<p>You have a <code>Shape<\/code> base class. Then, <code>Circle<\/code> and <code>Rectangle<\/code> both inherit from <code>Shape<\/code>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\n\/\/ Base class\nclass Shape {\npublic:\n    void display() {\n        std::cout &amp;lt;&amp;lt; &quot;This is a shape.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Derived class 1\nclass Circle : public Shape {\npublic:\n    void drawCircle() {\n        std::cout &amp;lt;&amp;lt; &quot;Drawing a circle.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\n\/\/ Derived class 2\nclass Rectangle : public Shape {\npublic:\n    void drawRectangle() {\n        std::cout &amp;lt;&amp;lt; &quot;Drawing a rectangle.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Circle myCircle;\n    myCircle.display(); \/\/ Inherited from Shape\n    myCircle.drawCircle();\n\n    Rectangle myRectangle;\n    myRectangle.display(); \/\/ Inherited from Shape\n    myRectangle.drawRectangle();\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">This is a shape.\nDrawing a circle.\nThis is a shape.\nDrawing a rectangle.<\/pre>\n\n\n\n<p>Both <code>Circle<\/code> and <code>Rectangle<\/code> reuse the <code>display()<\/code> method from <code>Shape<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-hybrid-virtual-inheritance\">5. Hybrid (Virtual) Inheritance<\/h3>\n\n\n\n<p>Hybrid inheritance combines two or more types of inheritance. A common form is combining multiple and hierarchical inheritance. This can lead to the \"Diamond Problem\" where a class inherits common members from two parent classes that themselves share a common grandparent class. C++ solves this using virtual base classes.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp.webp\"><img decoding=\"async\" width=\"814\" height=\"916\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp.webp\" alt=\"Hybrid (Virtual) Inheritance in C++\" class=\"wp-image-108760\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp.webp 814w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp-267x300.webp 267w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp-768x864.webp 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/hybrid-inheritance-cpp-150x169.webp 150w\" sizes=\"(max-width: 814px) 100vw, 814px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"the-diamond-problem\">The Diamond Problem:<\/h4>\n\n\n\n<p>Consider <code>A<\/code> as a base class. <code>B<\/code> and <code>C<\/code> inherit from <code>A<\/code>. Then, <code>D<\/code> inherits from both <code>B<\/code> and <code>C<\/code>. <code>D<\/code> gets two copies of <code>A<\/code>'s members.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\nclass A {\npublic:\n    A() { std::cout &amp;lt;&amp;lt; &quot;A&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n    void func() { std::cout &amp;lt;&amp;lt; &quot;A&#039;s function.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass B : public A {\npublic:\n    B() { std::cout &amp;lt;&amp;lt; &quot;B&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass C : public A {\npublic:\n    C() { std::cout &amp;lt;&amp;lt; &quot;C&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass D : public B, public C {\npublic:\n    D() { std::cout &amp;lt;&amp;lt; &quot;D&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nint main() {\n    D obj;\n    \/\/ obj.func(); \/\/ Ambiguous call\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>The call <code>obj.func()<\/code> is ambiguous because <code>D<\/code> has two <code>func()<\/code> methods, one from <code>B<\/code> and one from <code>C<\/code>. Both originate from <code>A<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"solution-virtual-base-classes\">Solution: Virtual Base Classes<\/h4>\n\n\n\n<p>You use the <code>virtual<\/code> keyword to make <code>A<\/code> a virtual base class for <code>B<\/code> and <code>C<\/code>. This ensures <code>D<\/code> gets only one copy of <code>A<\/code>'s members.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\nclass A {\npublic:\n    A() { std::cout &amp;lt;&amp;lt; &quot;A&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n    void func() { std::cout &amp;lt;&amp;lt; &quot;A&#039;s function.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass B : virtual public A { \/\/ Virtual inheritance\npublic:\n    B() { std::cout &amp;lt;&amp;lt; &quot;B&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass C : virtual public A { \/\/ Virtual inheritance\npublic:\n    C() { std::cout &amp;lt;&amp;lt; &quot;C&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nclass D : public B, public C {\npublic:\n    D() { std::cout &amp;lt;&amp;lt; &quot;D&#039;s constructor called.&quot; &amp;lt;&amp;lt; std::endl; }\n};\n\nint main() {\n    D obj;\n    obj.func(); \/\/ Now works\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">A's constructor called.\nB's constructor called.\nC's constructor called.\nD's constructor called.\nA's function.<\/pre>\n\n\n\n<p>Using <code>virtual<\/code> ensures only one <code>A<\/code> sub-object exists within <code>D<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"best-practices-for-inheritance\">Best Practices for Inheritance<\/h2>\n\n\n\n<p>Use these tips to make your inheritance code better:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Favor Composition Over Inheritance:<\/b> Use inheritance when a clear \"is-a\" relationship exists (e.g., Car is a Vehicle). Use composition when a \"has-a\" relationship exists (e.g., Car has an Engine). Composition often leads to more flexible designs.<\/li>\n\n\n\n<li><b>Keep Base Classes Simple:<\/b> Design base classes with common, generic functionality. Avoid adding too many specific details.<\/li>\n\n\n\n<li><b>Use protected for Internal Access:<\/b> Use protected members when derived classes need to access base class data, but external code should not.<\/li>\n\n\n\n<li><b>Define Clear Interfaces:<\/b> Ensure base classes provide a clear interface for derived classes to implement or override. Use virtual functions for this.<\/li>\n\n\n\n<li><b>Avoid Deep Inheritance Hierarchies:<\/b> Deep hierarchies become complex and difficult to manage. Keep your inheritance trees shallow.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Inheritance lets you create new classes from existing ones. This reuses code and builds relationships between classes. It helps you write less code and make programs easier to manage. This guide shows you how to use inheritance in C++ with clear steps and examples.<\/p>\n","protected":false},"author":41,"featured_media":34504,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36801],"content_type":[],"class_list":["post-34502","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-c-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Inheritance in C++: Types and Examples<\/title>\n<meta name=\"description\" content=\"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inheritance in C++\" \/>\n<meta property=\"og:description\" content=\"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-23T03:43:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-20T13:29:22+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1251\" \/>\n\t<meta property=\"og:image:height\" content=\"838\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Inheritance in C++\",\"datePublished\":\"2021-05-23T03:43:09+00:00\",\"dateModified\":\"2025-06-20T13:29:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/\"},\"wordCount\":732,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/iStock-488651322-2.jpg\",\"keywords\":[\"C++ Programming\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/\",\"name\":\"Inheritance in C++: Types and Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/iStock-488651322-2.jpg\",\"datePublished\":\"2021-05-23T03:43:09+00:00\",\"dateModified\":\"2025-06-20T13:29:22+00:00\",\"description\":\"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/iStock-488651322-2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/iStock-488651322-2.jpg\",\"width\":1251,\"height\":838,\"caption\":\"c++ inheritance\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/c-inheritance\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Inheritance in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Inheritance in C++: Types and Examples","description":"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"Inheritance in C++","og_description":"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-05-23T03:43:09+00:00","article_modified_time":"2025-06-20T13:29:22+00:00","og_image":[{"width":1251,"height":838,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Inheritance in C++","datePublished":"2021-05-23T03:43:09+00:00","dateModified":"2025-06-20T13:29:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/"},"wordCount":732,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg","keywords":["C++ Programming"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/","url":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/","name":"Inheritance in C++: Types and Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg","datePublished":"2021-05-23T03:43:09+00:00","dateModified":"2025-06-20T13:29:22+00:00","description":"C++ inheritance is defined as a mechanism in which one class can access the property and attributes from an existing class.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg","width":1251,"height":838,"caption":"c++ inheritance"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/c-inheritance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Inheritance in C++"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg",1251,838,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-300x201.jpg",300,201,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-768x514.jpg",768,514,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-1024x686.jpg",1024,686,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg",1251,838,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2.jpg",1251,838,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-640x838.jpg",640,838,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/05\/iStock-488651322-2-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Inheritance lets you create new classes from existing ones. This reuses code and builds relationships between classes. It helps you write less code and make programs easier to manage. This guide shows you how to use inheritance in C++ with clear steps and examples.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/34502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=34502"}],"version-history":[{"count":4,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/34502\/revisions"}],"predecessor-version":[{"id":108762,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/34502\/revisions\/108762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/34504"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=34502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=34502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=34502"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=34502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}