Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created Jan 24, 2018
Embed
What would you like to do?
#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