online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> class Base { public: // From https://stackoverflow.com/a/9779391/1270789 template<typename T, typename R> R proxycall(T *obj, R (T::*mf)(int)) { return (obj->*mf)(42); } // My attempt template<typename T, typename R> R proxycall(R (T::*mf)(int)) { return ((dynamic_cast<T *>(this))->*mf)(42); } virtual ~Base() {} }; class Foo: public Base { public: int doFoo(int x) { std::cout << "doing foo\n"; return x / 2; } int doCall() { return proxycall(this, &Foo::doFoo); } // OK int doNoThisCall() { return proxycall(&Foo::doFoo); } // Is this OK? }; int main() { Foo foo; std::cout << foo.doCall() << '\n'; std::cout << foo.doNoThisCall() << '\n'; 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