struct A { A(int& a) : m_a(a) {} void print() { std::cout << m_a << std::endl; } int& m_a; }; int main(int argc, char* argv[]) { int* b = new int(); *b = 1234567890; A a(*b); a.print(); *b = 43210; a.print(); delete b; a.print(); return 0; }
prints the following:
1234567890 43210 -572662307