Skip to content

Instantly share code, notes, and snippets.

@Infinitusvoid
Created January 15, 2023 20:53
Show Gist options
  • Save Infinitusvoid/2a5db4ce22453916c84e181849da76de to your computer and use it in GitHub Desktop.
Save Infinitusvoid/2a5db4ce22453916c84e181849da76de to your computer and use it in GitHub Desktop.
C++ : Pure virtual functions ( Interfaces )
#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