online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include "A.hpp" int main() { B b; std::cout << b.bar(); // Works fine, prints 2 std::cout << b.foo(); // WORKS FINE, Prints 1 }
#pragma once class A_data { public: int foo = 1; virtual ~A_data() = default; }; template <class C = A_data> class A { public: int foo() const; // Not implemented here A() { d = new C; } ~A() { delete d; } C* d; }; class B_data : public A_data { public: int bar = 2; virtual ~B_data() = default; }; // Template here is in case something needs to inherit B, like in A. template <class C = B_data> class B : public A<C> { public: int bar() const; // Not implemented here, just like A::foo. };
#include "A.hpp" //----------------vvvvvv---------------------------------->changed from A_data to B_data template <> int A<B_data>::foo() const { return d->foo; } template <> int B<B_data>::bar() const { return d->bar; }

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