online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include <memory> #include <type_traits> #include <assert.h> using namespace std; struct Base { virtual int get_thing_one() { return 0; } virtual int get_thing_two() { return 0; } virtual int get_thing_three() { return 0; } virtual int get_thing_four() { return 0; } }; struct A : public Base { virtual int get_thing_one() override { return 1; } virtual int get_thing_three() override { return 3; } }; struct B : public Base { virtual int get_thing_one() override { return 2; } virtual int get_thing_four() override{ return 4; } }; // example simple factory std::shared_ptr<Base> get_class(const int input) { switch(input) { case 0: return std::shared_ptr<Base>(std::make_shared<A>()); break; case 1: return std::shared_ptr<Base>(std::make_shared<B>()); break; default: assert(false); break; } } class setter { private: std::shared_ptr<Base> l_ptr; public: setter(const std::shared_ptr<Base>& input):l_ptr(input) {} int get_thing_a() { return l_ptr->get_thing_one() + l_ptr->get_thing_two(); } int get_thing_b() { return l_ptr->get_thing_three() + l_ptr->get_thing_four(); } }; int main() { constexpr int select = 0; std::shared_ptr<Base> example = get_class(select); setter l_setter(example); std::cout << l_setter.get_thing_a() << std::endl; std::cout << l_setter.get_thing_b() << std::endl; 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.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue