your code is problematic. Because it is going out of scope ou return an destroyed object.
I prefer two solution
B* GetObject()
{
B *b = new B(5);
return b;
}
bool FillObject(B& b)
{
b.value = 5;
return true;}
FillObject(theObject);
why dont your write only
B *b = new B(5);
???