{}
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
run-icon
main.cpp
// Online C++ compiler to run C++ program online #include <iostream> class X { public: X() { std::cout << "X constructed" << std::endl; } ~X() { std::cout << "X destroyed" << std::endl; } X& get() { return *this; } int get_i() { std::cout << "getting i" << std::endl; return i; } private: int i = 7; }; int main() { int val = X().get().get_i(); std::cout << val << std::endl; std::cout << "now lets break it" << std::endl; auto& x = X().get(); // This is accessing destroyed mem. std::cout << x.get_i(); return 0; }
Output