/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <memory>
struct A;
struct B{
std::shared_ptr<A> sp;
~B(){ std::cout << "B destroyed\n"; }
};
struct A{
std::shared_ptr<B> sp;
~A(){ std::cout << "A destroyed\n"; }
};
int main(){
std::shared_ptr<B> b{};
std::shared_ptr<A> a {b->sp};
b = a->sp;
}