Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created January 24, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulev/fad7c4972b5dd3aea38bb96404a56a17 to your computer and use it in GitHub Desktop.
Save pkulev/fad7c4972b5dd3aea38bb96404a56a17 to your computer and use it in GitHub Desktop.
#include <map>
#include <iostream>
using namespace std;
class NetworkInterface {
public:
int a = 5;
NetworkInterface(int a): a(a) {}
};
class SubnetInterface : public NetworkInterface {
public:
SubnetInterface(int a): NetworkInterface(a * 10) {}
};
class SwitchInterface : public NetworkInterface {
public:
SwitchInterface(int a): NetworkInterface(a * 100) {}
};
int main() {
std::map<std::string, NetworkInterface> interfaces = {
{"subnet", SubnetInterface(1)},
{"switch", SwitchInterface(1)},
};
NetworkInterface ni = NetworkInterface(10);
cout << "ablabla: " << ni.a << endl;
SubnetInterface si = SubnetInterface(10);
cout << "blablab: " << si.a << endl;
SwitchInterface swi = SwitchInterface(10);
cout << "aaaaaaa: " << swi.a << endl;
cout << interfaces["subnet"].a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment