online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <variant> #include <algorithm> #include <vector> class EmptyDevice { public: void print_me()const { std::cout<<"EmptyDevice"<<'\n'; } }; class Pin { public: void print_me()const { std::cout<<"Pin"<<'\n'; } }; class UART { public: void print_me()const { std::cout<<"UART"<<'\n'; } }; class SoftUART { public: void print_me()const { std::cout<<"SoftUART"<<'\n'; } }; using ControlWay=std::variant<EmptyDevice,Pin,UART,SoftUART>; class DeviceList { std::vector<ControlWay*> m_list; public: bool addDevice(ControlWay* device) { m_list.push_back(device); return true; } bool removeDevice(ControlWay* device) { m_list.erase(std::remove(m_list.begin(),m_list.end(),device),m_list.end()); return true; } void print_me()const { for(auto* d:m_list) { std::visit([](auto& device) { device.print_me(); },*d); } } }; int main() { DeviceList m_DeviceList; m_DeviceList.addDevice(new ControlWay{Pin{}}); m_DeviceList.addDevice(new ControlWay{UART{}}); m_DeviceList.addDevice(new ControlWay{SoftUART{}}); m_DeviceList.print_me(); //m_DeviceList.removeDevice(d1); //m_DeviceList.removeDevice(d2); //m_DeviceList.removeDevice(d3); //не забыть сделать освобождение памяти либо заюзать std::unique_ptr return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text



Program is not being debugged. Click "Debug" button to start program in debug mode.