online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <string> struct expr_t { virtual ~expr_t() {} }; struct ident_t : public expr_t { std::string name; ident_t(std::string name) : name(name) {} }; //moved the 2nd overload above first overload std::string to_string(ident_t& v) { return v.name; } std::string to_string(expr_t& v) { if (auto* id = dynamic_cast<ident_t*>(&v)) { return to_string(*id); //now compiler knows about std::string to_string(ident_t& v) } return "error"; } int main() { expr_t* b = new ident_t("c"); std::cout << to_string(*b) << std::endl; // segfault delete b; 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