Created
January 15, 2023 20:53
-
-
Save Infinitusvoid/2a5db4ce22453916c84e181849da76de to your computer and use it in GitHub Desktop.
C++ : Pure virtual functions ( Interfaces )
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> | |
#include <string> | |
struct IDescription | |
{ | |
virtual std::string get_description() = 0; | |
}; | |
struct Gallery : public IDescription | |
{ | |
std::string get_description() override | |
{ | |
return "I am gallery."; | |
} | |
}; | |
struct Airport : public IDescription | |
{ | |
std::string get_description() override | |
{ | |
return "I am airport."; | |
} | |
}; | |
void display(IDescription& description) | |
{ | |
std::cout << description.get_description() << std::endl; | |
} | |
int main() | |
{ | |
//IDescription decripton; // It's an interface we can instanciate it | |
Gallery galley; | |
Airport airport; | |
display(galley); // airport | |
display(airport); // description | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment