Last active
September 17, 2020 17:28
-
-
Save Adobe-Android/dc78fd9679e91dc4d0f2a3e826491205 to your computer and use it in GitHub Desktop.
A simple demonstration of inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct Superclass { | |
int x{}; | |
}; | |
struct Subclass : public Superclass { | |
public: | |
int y{}; | |
int foo() { return x + y; } | |
}; | |
int main() { | |
Subclass sub; | |
sub.x = 2; | |
sub.y = 2; | |
std::cout << sub.foo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment