online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <memory> class Base { private: int _v1; public: Base(int v) : _v1(v) { std::cout << "Base::Ctor " << std::endl;} virtual int GetVal() { std::cout << "Base::GetVal() \t"; return _v1; } }; class Derived : public Base { private: int _v1; public: Derived(int v) : Base(v), _v1(v) { std::cout << "Derived::Ctor " << std::endl; } int GetVal() override{ std::cout << "Derived::GetVal() \t"; return _v1; } }; // Pass by Value int GetDerived3(std::unique_ptr<Base> ptr) { std::cout << "GetDerived3()\t" << "ptr.get() " << ptr.get() << " " << ptr->GetVal() << std::endl; return 1; } // Pass by reference int GetDerived4(std::unique_ptr<Base> & ptr) { std::cout << "GetDerived4()\t" << ptr->GetVal() << std::endl; return 1; } int main() { auto a = std::make_unique<Derived>(23); std::cout << "main() a \t" << "a.get() " << a.get() << std::endl; GetDerived3(std::move(a)); //GetDerived4(a); std::cout << "After move in main() a \t" << "a.get() " << a.get() << "\n\n"; std::unique_ptr<Base> b = std::make_unique<Derived>(24); std::cout << "main() b \t" << "b.get() " << b.get() << " " << b->GetVal() << std::endl; GetDerived4(b); std::cout << "After passing to GetDerived4\t" << "b.get() " << b.get() << " " << b->GetVal() << std::endl; return 1; }

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